gpt4 book ai didi

javascript - 在 Unity 3D 上使用 Google map API v3

转载 作者:行者123 更新时间:2023-12-03 08:13:20 24 4
gpt4 key购买 nike

我需要在 Unity 3D 应用程序上插入 Google map 中的 map 。

我认为可以使用 JavaScript API v3,但我不知道如何开始。

谢谢你

最佳答案

您必须使用google static unity3d 中的图像 api,您还需要在 google 上注册才能获取api key。或者您可以使用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.012318&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());
}

记住Google 不允许免费访问大于640x640 的图像。

关于javascript - 在 Unity 3D 上使用 Google map API v3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34053610/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com