I am trying to use a navigation menu that connects the links to a marker on google maps. When it is clicked, the map centers itself on the marker that corresponds to the link clicked. I saw this great example, http://www.cannonade.net/geo.php?test=geo20, but was confused by the source code and the fact that it was for a sidebar. I would like my navigation above开发者_运维问答 the map.
With Page Refresh
If you plan on moving to a new page (ie, a profile for a new location) then you simply have to store the LatLng of the marker either in the link or to be pushed to javascript from the server side code.
After that, you can simply create your map as usual with:
map.setCenter(latlng);
Map Reference
Without Page Refresh
If you don't plan on refreshing the page, just moving the map - you can use panTo(latlng)
instead.
It might look something like this:
<a href="javascript: map.panTo(new LatLng(25.2, 105.7))">Mexico</a>
精彩评论