Reputation: 41
I need to insert maps from Google Maps on a Unity 3D Application.
I think can be use API v3 for JavaScript but i don't know how begin.
Thanks you
Upvotes: 0
Views: 5835
Reputation: 10541
You have to use google static image api in unity3d and you also need to register on google for getting api key. Or you can use this free asset store package but you have to purchase uniWeb as well. I use this Simple Code snippet for getting google image on a gameobject below:
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());
}
Remember Google not allowed Free access of greater then 640x640 Image.
Upvotes: 1