Using google maps API, how can we set the current location as the default set location using map.setCenter function?

前端 未结 7 1435

I am writing JavaScript code using Google Maps API.

map = new google.maps.Map2(document.getElementById(\"map_canvas\"));
map.setCenter(new google.maps.LatLng         


        
7条回答
  •  情话喂你
    2020-12-25 14:22

    that already exists in the google api:

    if (GBrowserIsCompatible()) 
    {   
        var map = new google.maps.Map2(document.getElementById("mapdiv"));
    
        if (google.loader.ClientLocation) 
        {        
            var center = new google.maps.LatLng(
                google.loader.ClientLocation.latitude,
                google.loader.ClientLocation.longitude
            );
            var zoom = 8;
    
            map.setCenter(center, zoom);
        }
    }
    

    There are several threads with the same question...

提交回复
热议问题