最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I get the URL for Google Map embedded on my website? - Stack Overflow

programmeradmin9浏览0评论

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
  • How are you displaying the map? Don't you use the same URL to display map? – Shoban Commented Dec 11, 2009 at 19:11
  • With the API you don't need to have a URL, you just set latitude and longitude and the map displays in your specified DIV element. I'm trying to get the URL that would display that map without the API. – spig Commented Dec 11, 2009 at 19:14
  • I ended up using information given by two of the answers. In the end I used jQuery and retrieved the information from the map object to create a new URL passed into window.open. 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
Add a comment  | 

3 Answers 3

Reset to default 8

This 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>

发布评论

评论列表(0)

  1. 暂无评论