0
我需要在Unity 3D應用程序中插入Google地圖上的地圖。在Unity 3D上使用Google Maps API v3
我認爲可以使用JavaScript v3的JavaScript,但我不知道如何開始。
感謝您
我需要在Unity 3D應用程序中插入Google地圖上的地圖。在Unity 3D上使用Google Maps API v3
我認爲可以使用JavaScript v3的JavaScript,但我不知道如何開始。
感謝您
你必須使用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圖片免費使用。
嗨,我用這個代碼和工作,但標記不顯示。我創建了一個API密鑰瀏覽器,這沒關係? – SergiPanadero
,因爲url不包含標記選項。閱讀答案中提到的API鏈接。 –
或者您可以使用此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 –