0

I am trying to redraw image after every 10 seconds. by using

 $(document).ready(function() {
setInterval("marker()",10000);
});

but marker() function inside initialize() function how can i access only marker to work it for above setInterval

 function initialize(x,y) {
  var myLatlng = new google.maps.LatLng(x,y);
  var mapOptions = {
  zoom: 4,
  center: myLatlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
 }
 var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
 marker(x,y);
 function marker(){
   var image = 'myimage.png';
   var myLatLng = new google.maps.LatLng(x, y);
   var beachMarker = new google.maps.Marker({
   position: myLatLng,
   map: map,
   icon: image
   });
 }
}

2
  • Do not pass strings to setInterval, but the function itself! Commented Mar 7, 2013 at 20:11
  • you can call setInterval(marker, 10000); Commented Mar 7, 2013 at 20:11

1 Answer 1

1

Just change it to

setInterval(marker, 10000);

and move that into a scope where the marker function is available, i.e. into initialize.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.