xmux xmux - 7 months ago 32
Javascript Question

How can i jump from another web page (with an url) to a specific LatLong or to a marker on my self-created google maps (v3 JS API)?

I found a simple example, but this works only if the map and the link on the same page.

HTML

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry,visualization,drawing,places"></script>

<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(51.522387,-0.173501);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);

var marker2 = new google.maps.Marker(
{
position: new google.maps.LatLng(51.5262405, -0.074549),
map: map,
title: "my 2nd title"
}
);

google.maps.event.addDomListener(
document.getElementById("marker2"), "click", function() {
map.setCenter(marker2.getPosition());
return false;
}
);
}

</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:310px; height:260px"></div>
<a href="#" id="marker2">Second place</a>
</body>
</html>


Is there a way to jump to a specific location (LatLong) or directly to a marker with marker.getPosition() from another website to my self created GM Map?

Maybe with an anchor? Ex: http://www.example.com/map#marker2

Answer

Here example to get value of query from URL jquery get querystring from URL

Use this to inserted your code and use

map.setCenter(new gooogle.map.latlng(0,0));

for setting center map to location of marker