Jump to content

google map - moving a marker


michaellunsford

Recommended Posts

I've been hacking on this for days and I just can't get the right google search to find the answer.

 

Basically, I want to move a map marker after the map initialization function runs. The marker variable is local to the function, so I get "map.marker1 is undefined" in firebug. So, I add a global "var marker1,map;" and still the error persists.

 

In the example below, the panTo works fine in the map, but the marker doesn't.  :confused:

 

<script type="text/javascript" src="/ads/jquery-1.5.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
var map;
var marker1;
$(document).ready(function() {
	initialize(30.2240897,-92.0198427);
	setTimeout('map.panTo(new google.maps.LatLng(30.22,-92.01));',5000);
	setTimeout('map.marker1.setPosition(new google.maps.LatLng(30.22,-92.01));',5000);
});
function initialize(thelat,thelng) {
	var latlng = new google.maps.LatLng(thelat,thelng);
	var myOptions = {
		zoom: 12,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

	var myLatlng1 = new google.maps.LatLng(thelat, thelng);
	var contentString1 = 'test marker';
	var marker1 = new google.maps.Marker({
		position: myLatlng1,
		map: map,
		title: contentString1
	});
	var infowindow1 = new google.maps.InfoWindow({
		content: contentString1
	});
	google.maps.event.addListener(marker1, 'click', function() {
		infowindow1.open(map,marker1);
	});
}
</script>
<div id="map_canvas" style="width:auto; height:90%;"></div>

Link to comment
https://forums.phpfreaks.com/topic/227276-google-map-moving-a-marker/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.