I am displaying a map on a website using the Google Map API. I want to include a link on that same page to take them directly to the map on Google Maps.
Is there an API call I can make to the map to retrieve the URL of either the current location/zoom level or the starting location/zoom level?
I am displaying a map on a website using the Google Map API. I want to include a link on that same page to take them directly to the map on Google Maps.
Is there an API call I can make to the map to retrieve the URL of either the current location/zoom level or the starting location/zoom level?
Share Improve this question edited Mar 23, 2010 at 22:44 Daniel Vassallo 344k72 gold badges512 silver badges446 bronze badges asked Dec 11, 2009 at 19:06 spigspig 1,7156 gold badges22 silver badges30 bronze badges 3 |3 Answers
Reset to default 8This is the link to use to centre Google Maps to a point:
http://maps.google.com/?ll=LATITUDE,LONGITUDE&z=ZOOM
All you need to do is to replace the above LATITUDE
, LONGITUDE
and ZOOM
with the required coordinates.
To get the latitude and longitude where the mouse is clicked, you could use the following API code:
var map = new GMap2(document.getElementById("map_canvas"));
GEvent.addListener(map,"click", function(overlay, latlng) {
if (latlng) {
// latlng defines the latitude and longitude where the mouse was clicked.
}
});
You don't need to use the API. From Google maps, click the Link
link in the upper right corner, and copy the code for Paste HTML to embed in website
and throw that in your page and it should be what you want. It puts in the link to see the larger map on Google maps. You can also click the Customize and preview embedded map
link to see more options. It will display your map at whatever zoom and location you set it to.
This should give you all the query parameters you could want: http://mapki.com/wiki/Google_Map_Parameters
Then just make a link pointing at maps.google.com?<INSERT_PARAMS_HERE>
window.open("http://maps.google.com/?ll="+map.getCenter().toUrlValue()+"&z="+map.getZoom()+"&t="+map.getCurrentMapType().getUrlArg(), "largermap");
– spig Commented Dec 11, 2009 at 21:51