Click here to Skip to main content
16,007,932 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to move marker after some interval on map..
i have following code for the same...but i want to do it with some type of array of latitude and longitude points so marker is move on many points on map...
here is my code...thank u for help !!!!


C#
var map;
     function initialize()
     {
       var latlng = new google.maps.LatLng(21.16536,72.79387);

       var NewLatLng = new google.maps.LatLng(20.371237, 72.90634);
       var NewLatLng1 = new google.maps.LatLng(19.9974533, 73.78980230);

       var myOptions = {
           zoom: 5,
           center: latlng,
           mapTypeId: google.maps.MapTypeId.ROADMAP
       };
       map = new google.maps.Map(document.getElementById("map"), myOptions);
       var marker = new google.maps.Marker
       (
           {
               position: new google.maps.LatLng(21.1673643, 72.7851802),
               map: map,
               title: 'Click me'
           }

       );
           setInterval(function() { marker.setPosition(NewLatLng);}, 2000);
           setInterval(function() { marker.setPosition(NewLatLng1);}, 7000);

       var infowindow = new google.maps.InfoWindow({
           content: 'Location info:<br/>SVNIT Post Office, Dumas Rd, Surat<br/>LatLng:<br/>21.1673643, 72.7851802'
       });
       google.maps.event.addListener(marker, 'click', function ()
       {
          infowindow.open(map, marker);
          setTimeout(function(){infowindow.close();}, '5000');
       });
   }
   window.onload = initialize;
Posted

1 solution

Try this

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
var locations=[
['19.0018014','72.914170300'],['18.4915595','73.886065199'],['17.5272371','75.957780299'],['19.0787678','75.752507899'],['19.9971895','73.916395800'],['19.0150482','72.855971599']
];

var map;
var NewLatLng=[];
var markers=[];
var marker ;
function initialize()
{
var latlng = new google.maps.LatLng(21.16536,72.79387);
var myOptions = {
zoom: 5,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
marker = new google.maps.Marker
(
{
position: new google.maps.LatLng(21.1673643, 72.7851802),
map: map,
title: 'Click me'
}

);
markers.push(marker);
$.each(locations, function (i, item) {
NewLatLng.push(new google.maps.LatLng(item[0], item[1]));
});


var infowindow = new google.maps.InfoWindow({
content: 'Location info:
SVNIT Post Office, Dumas Rd, Surat
LatLng:
21.1673643, 72.7851802'
});
google.maps.event.addListener(marker, 'click', function ()
{
infowindow.open(map, marker);
setTimeout(function(){infowindow.close();}, '5000');
});
$.each(NewLatLng, function (i, item) {
setTimeout(function(){
marker.setPosition(item);

markers.push(marker);

}, i*1000);

});
}


window.onload = initialize;

</script>
 
Share this answer
 
Comments
Member 9332883 27-Sep-12 7:12am    
it does not show map...:(
Member 10872438 26-Jun-14 1:19am    
me too have any soln...?pls help!!!
Member 9332883 27-Sep-12 7:14am    
thank u...many 10000 times..it works...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900