SergiPanadero SergiPanadero - 8 months ago 120
Javascript Question

use Google Maps API v3 on Unity 3D

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

Answer Source

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 = "" + lat + "," + lon +
                "&zoom=" + zoom + "&size=" + mapWidth + "x" + mapHeight + "&scale=" + scale 
                +"&maptype=" + mapSelected +
            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()


Remember Google not allowed Free access of greater then 640x640 Image.