Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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...and also shows the direction among that points...
here is my code...thank u for help !!!!

var locations=[
['19.0018014','72.914170300']'
['18.4915595','73.886065199'],
['17.5272371','75.957780299'],
['19.0787678','75.752507899'],
['19.9971895','73.916395800'],
['21.16536','72.79387']
];
 
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);
        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:<br/>Movable Marker !!'

        });
        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*3000);

        });
    
    }
    window.onload =initialize;
Posted

1 solution

If you need to display the path between those marker points try this...

C#
var locations=[
['19.0018014','72.914170300']'
['18.4915595','73.886065199'],
['17.5272371','75.957780299'],
['19.0787678','75.752507899'],
['19.9971895','73.916395800'],
['21.16536','72.79387']
];

var map;
var NewLatLng=[];
var NewLatLng1=[]
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);
        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:<br/>Movable Marker !!'

        });
        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);
NewLatLng1.push(item);
 var flightPath = new google.maps.Polyline({
          path: NewLatLng1,
          strokeColor: '#FF0000',
          strokeOpacity: 1.0,
          strokeWeight: 2
        });
 flightPath.setMap(map);
            }, i*3000);

        });





    }
    window.onload =initialize;
 
Share this answer
 
Comments
Member 9332883 2-Oct-12 9:15am    
but i want to show direction not line between those marker...how i can do that ??

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