質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.51%
Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Google マップ

Google Mapは、Google社がオンラインで提供している地図・ローカル検索サービスです。GIS(Geographic Information System:地理情報システム)の中の「WebGIS」に該当します。地図・航空写真・地形の表示方式があり、それぞれユーザーが縮尺を調整して表示させることができます。地域の情報サービスを検索する機能やルート検索の機能も搭載されています。

Q&A

0回答

1970閲覧

[Unity] Google mapをUnity上で表示させる方法

pasui

総合スコア4

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Google マップ

Google Mapは、Google社がオンラインで提供している地図・ローカル検索サービスです。GIS(Geographic Information System:地理情報システム)の中の「WebGIS」に該当します。地図・航空写真・地形の表示方式があり、それぞれユーザーが縮尺を調整して表示させることができます。地域の情報サービスを検索する機能やルート検索の機能も搭載されています。

0グッド

0クリップ

投稿2019/09/28 17:48

現在オライリー・ジャパンの書籍"UnityによるARゲーム開発"という本を読んで勉強しています

###問題
イメージ説明
これはPlaneをつくってからGoogleMapTileでGoogleMapを表示させようとしています。

発生している問題・エラーメッセージ

別の質問でも同じようなエラーが出ている人がいたのですが
イメージ説明
このようなエラーが出てマップがUnity上の表示されません。

該当のソースコード

C#

1using UnityEngine; 2using UnityEngine.Networking; 3using System.Collections; 4using packt.FoodyGo.Mapping; 5using packt.FoodyGo.Services; 6 7namespace packt.FoodyGO.Mapping 8{ 9 [AddComponentMenu("Mapping/GoogleMapTile")] 10 public class GoogleMapTile : MonoBehaviour 11 { 12 public enum MapType 13 { 14 RoadMap, 15 Satellite, 16 Terrain, 17 Hybrid 18 } 19 20 //Google Maps API Staticmap URL 21 private const string GOOGLE_MAPS_URL = "https://maps.googleapis.com/maps/api/staticmap"; 22 23 [Header("Map Settings")] 24 [Range(1,20)] 25 [Tooltip("Zoom Level, 1=global - 20=house")] 26 public int zoomLevel = 1; 27 [Tooltip("Type of map, Road, Satellite, Terrain or Hybrid")] 28 public MapType mapType = MapType.RoadMap; 29 [Range(64,1024)] 30 [Tooltip("Size in pixels of the map image")] 31 public int size = 640; 32 [Tooltip("Double the pixel resolution of the image returned")] 33 public bool doubleResolution = true; 34 35 public MapLocation worldCenterLocation; 36 37 [Header("Tile Settings")] 38 [Tooltip("Sets the tiles position in tile units")] 39 public Vector2 TileOffset; 40 [Tooltip("Calculated tile center")] 41 public MapLocation tileCenterLocation; 42 [Tooltip("Calculated tile corners")] 43 public Vector2 TopLeftCorner; 44 public Vector2 BottomRightCorner; 45 46 [Header("GPS Settings")] 47 [Tooltip("GPS service used to locate world center")] 48 public GPSLocationService gpsLocationService; 49 public string API_KEY; 50 private double lastGPSUpdate; 51 52 // Use this for initialization 53 void Start () 54 { 55 RefreshMapTile (); 56 } 57 58 // Update is called once per frame 59 void Update () 60 { 61 // 新しい位置が取得されたかどうかを確認する 62 if (gpsLocationService != null && 63 gpsLocationService.IsServiceStarted && 64 lastGPSUpdate < gpsLocationService.Timestamp) 65 { 66 lastGPSUpdate = gpsLocationService.Timestamp; 67 worldCenterLocation.Latitude = gpsLocationService.Latitude; 68 worldCenterLocation.Longitude = gpsLocationService.Longitude; 69 print("GoogleMapTile refreshing map texture"); 70 RefreshMapTile(); 71 } 72 } 73 74 public void RefreshMapTile() { 75 76 StartCoroutine(_RefreshMapTile()); 77 } 78 79 IEnumerator _RefreshMapTile () 80 { 81 // タイル中心の緯度/経度を取得 82 tileCenterLocation.Latitude = GoogleMapUtils.adjustLatByPixels(worldCenterLocation.Latitude, (int)(size * 1 * TileOffset.y), zoomLevel); 83 tileCenterLocation.Longitude = GoogleMapUtils.adjustLonByPixels(worldCenterLocation.Longitude, (int)(size * 1 * TileOffset.x), zoomLevel); 84 85 var url = GOOGLE_MAPS_URL; 86 var queryString = ""; 87 88 // 地図タイルをリクエストするクエリ文字列パラメーターを作成する 89 queryString += "center=" + WWW.UnEscapeURL (string.Format ("{0},{1}", tileCenterLocation.Latitude, tileCenterLocation.Longitude)); 90 queryString += "&zoom=" + zoomLevel.ToString (); 91 queryString += "&size=" + WWW.UnEscapeURL (string.Format ("{0}x{0}", size)); 92 queryString += "&scale=" + (doubleResolution ? "2" : "1"); 93 queryString += "&maptype=" + mapType.ToString ().ToLower (); 94 queryString += "&format=" + "png"; 95 96 // 地図のスタイルを追加する 97 queryString += "&style=element:geometry|invert_lightness:true|weight:3.1|hue:0x00ffd5"; 98 queryString += "&style=element:labels|visibility:off"; 99 100 var usingSensor = false; 101#if MOBILE_INPUT 102 usingSensor = Input.location.isEnabledByUser && Input.location.status == LocationServiceStatus.Running; 103#endif 104 105 queryString += "&sensor=" + (usingSensor ? "true" : "false"); 106 queryString += "&key =" + API_KEY; 107 108 //set map bounds rect 109 TopLeftCorner.x = GoogleMapUtils.adjustLonByPixels(tileCenterLocation.Longitude, -size, zoomLevel); 110 TopLeftCorner.y = GoogleMapUtils.adjustLatByPixels(tileCenterLocation.Latitude, size, zoomLevel); 111 112 BottomRightCorner.x = GoogleMapUtils.adjustLonByPixels(tileCenterLocation.Longitude, size, zoomLevel); 113 BottomRightCorner.y = GoogleMapUtils.adjustLatByPixels(tileCenterLocation.Latitude, -size, zoomLevel); 114 115 print(string.Format("Tile {0}x{1} requested with {2}", TileOffset.x, TileOffset.y, queryString)); 116 117 // 最後に、画像をリクエストする 118 var req = UnityWebRequestTexture.GetTexture(GOOGLE_MAPS_URL + "?" + queryString); 119 // サービスが応答するまで待つ 120 yield return req.SendWebRequest(); 121 // 最初に古いテクスチャーを破棄する 122 Destroy(GetComponent<Renderer>().material.mainTexture); 123 // エラーをチェックする 124 if (req.error != null) { 125 print (string.Format ("Error loading tile {0}x{1}: exception={2}", 126 TileOffset.x, TileOffset.y, req.error)); 127 } else { 128 // レンダリング画像がエラーがなければ戻ってきた画像をタイルテクスチャーとして設定する 129 GetComponent<Renderer> ().material.mainTexture = ((DownloadHandlerTexture)req.downloadHandler).texture; 130 print (string.Format ("Tile {0}x{1} textured", TileOffset.x, TileOffset.y)); 131 } 132 } 133 } 134} 135

試したこと

Google Static APIを取得して試してみたのですがやはり表示されませんでした

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.51%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問