开发者

How to create a hyperlink to a placemark on Google Maps?

开发者 https://www.devze.com 2023-03-09 07:10 出处:网络
The URL http://members.startupguild.net/#andrewdavey takes me to a Google Map and displays a placemark.

The URL http://members.startupguild.net/#andrewdavey takes me to a Google Map and displays a placemark.

Please can you tell me how to code this (or point me at some instructions). I have looked on these sites but can't see an answer:

  • http://code.google.com/apis/kml/documentation/kmlreferenc开发者_如何学编程e.html
  • http://code.google.com/apis/maps/documentation/javascript/reference.html


All you have to do is URL-encode some sort of an identifier for each of the overlays. In the example you show, #andrewdavey is that identifier. When the page loads, the javascript parses the identifier from the URL, and requests the corresponding marker/location with that ID, at which to open the info window.

A simple example would be something like:

var myLocations = new Array();
myLocations["#id1"] = new GLatLng(45,45);
myLocations["#id2"] = new GLatLng(15,35);
.
.
.

Then you'd look up the key: #id1, #id2, ... etc from the URL, and acquire the location as

var selectedLocation = myLocations[url_id];

You can then open an info window/do whatever at that location using the maps API. Note that the location on the map does not have to come from a hard coded array - it could be looked up from a data source for instance.

0

精彩评论

暂无评论...
验证码 换一张
取 消