2015-12-02 92 views

回答

1

你必须使用google static图像API中unity3d,你还需要对谷歌注册得到API密钥。或者您可以使用this免费资产商店套餐,但您必须购买uniWeb。 我用这个简单的代码片段上下方的游戏对象得到谷歌图片:

 string url = ""; 
     /// <summary> 
     /// Langitude/latitude of area. default Karachi is set 
     /// </summary> 
     public float lat = 24.917828f; 

     public float lon = 67.097096f; 
     LocationInfo li; 
     /// <summary> 
     /// Maps on Google Maps have an integer 'zoom level' which defines the resolution of the current view. 
     /// Zoom levels between 0 (the lowest zoom level, in which the entire world can be seen on one map) and 
     /// 21+ (down to streets and individual buildings) are possible within the default roadmap view. 
     /// </summary> 
     public int zoom = 14; 
     /// <summary> 
     /// not more then 640 * 640 
     /// </summary> 
     public int mapWidth = 640; 
     public int mapHeight = 640; 

     public enum mapType { roadmap, satellite, hybrid, terrain }; 
     public mapType mapSelected; 
     /// <summary> 
     /// scale can be 1,2 for free plan and can also be 4 for paid 
     /// </summary> 
     public int scale; 
IEnumerator GetGoogleMap() 
    { 
    url = "https://maps.googleapis.com/maps/api/staticmap?center=" + lat + "," + lon + 
       "&zoom=" + zoom + "&size=" + mapWidth + "x" + mapHeight + "&scale=" + scale 
       +"&maptype=" + mapSelected + 
       "&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.&markers=color:red%7Clabel:C%7C40.718217,-73.998284&key=YourAPIKeyWillbeHere"; 
      loadingMap = true; 
      WWW www = new WWW(url); 
      yield return www; 
      loadingMap = false; 
    //Assign downloaded map texture to any gameobject e.g., plane 
      gameObject.GetComponent<Renderer>().material.mainTexture = www.texture; 
} 
void Start() 
    { 

     StartCoroutine(GetGoogleMap()); 
    } 

Remembe [R谷歌不允许的大于640x640图片免费使用。

+0

嗨,我用这个代码和工作,但标记不显示。我创建了一个API密钥浏览器,这没关系? – SergiPanadero

+0

,因为url不包含标记选项。阅读答案中提到的API链接。 –

+0

或者您可以使用此URL(根据您的需求进行更新)https://maps.googleapis.com/maps/api/staticmap?center=Williamsburg,Brooklyn,NY&zoom=13&size=400x400& markers = color:blue%7Clabel :S%7C11211%7C11206%7C11222&key = YOUR_API_KEY –