現在オライリー・ジャパンの書籍"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を取得して試してみたのですがやはり表示されませんでした
あなたの回答
tips
プレビュー