Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.