1

Hi all I need to update google markers position every 5sec

I have this javascript code for drawing a google markers when page loads.

I want to be able to change position of the markers every 5 sec.

Here is my code:

function initialize() {
  var myOptions = {
    zoom: 4,
    center: new google.maps.LatLng(-25.363882, 131.044922),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };


  var map = new google.maps.Map(document.getElementById('map_canvas'),
      myOptions);

  var image = new google.maps.MarkerImage("images/truck3.png",
        new google.maps.Size(32.0, 37.0),
        new google.maps.Point(0, 0),
        new google.maps.Point(16.0, 18.0)
    );
  var shadow = new google.maps.MarkerImage("images/shadow-truck3.png",
        new google.maps.Size(51.0, 37.0),
        new google.maps.Point(0, 0),
        new google.maps.Point(16.0, 18.0)
    );

  var marker = new google.maps.Marker({
    position: map.getCenter(),
    map: map,
    icon: image,
    shadow: shadow,
    title: 'Click to zoom'
  });

google.maps.event.addDomListener(window, 'load', initialize);

One more thing how can I put multiple points when showing more then one marker. I know this is probably trivial for you but I am totally new at this.

EDIT:

I am sorry but this google got me tottaly confused. So What I want to do is next. When page loads I want to retrieve and array of last positions and each of that positions will have their id so an php array would be like array[Lat][Lng][id], after that I would like to put and marker on each of that position and put it in the center of the screen. When user clicks on one marker it will automatically zoom and start putting the marker position in the center every second. And I need an id for that certain marker.

This is a similar question, it would be nice if some java guru can combine me those to to get what I need

LINK ON THE SIMILAR QUESTION

Community
  • 1
  • 1
user123_456
  • 5,635
  • 26
  • 84
  • 140
  • This code put one marker in the center of map? – Alex Ball Jun 08 '12 at 13:29
  • Yes I will load a array from php with points , will the code be the same for one and for more markers? – user123_456 Jun 08 '12 at 13:30
  • I think you need to do a loop on the array, and manage the placement of markers, this show many markers, i think – Alex Ball Jun 08 '12 at 13:32
  • What do you mean by "how can I put multiple points when showing more then one marker?" What's a "point"? Do you want to update positions of more than one marker at the same time? – Heitor Chang Jun 08 '12 at 13:33
  • yes that's exactly what I want. I am sorry but this google got me tottaly confused. So What I want to do is next. When page loads I want to retrieve and array of last positions as an array and each of that positions will have their id so an php array would be like `array[Lat][Lng][id]`, after that I would like to put and marker on each of that position and put it in the center of the screen. When user clicks on one marker it will automatically zoom and start putting the marker in the center every second. And I need an id for that certain marker. OMG I hope you understand me a bit :) – user123_456 Jun 08 '12 at 13:37
  • The problem of retrieving the data from the JavaScript Array is covered in your 2 previous questions: http://stackoverflow.com/q/10931109/1314132 and http://stackoverflow.com/q/10950626/1314132. Please stop flooding this tag with the same question (this is the 3rd repeat of the PHP to JavaScript question). If this question is asking about the 5 second delay problem, try to confine the question to just that aspect of your problem. – Sean Mickey Jun 08 '12 at 15:18

3 Answers3

0

This google.maps.Marker method allows you to change the position of existing markers:

visit here setPosition(latlng:LatLng)

Create an array of the markers, loop through it updating their position.

geocodezip
  • 158,664
  • 13
  • 220
  • 245
0

well you can get lot of support for your queries GOOGLE MAPS API V3 Documentation

there are functions like setCenter(latlng) that changes center on run time and also the function setPosition(latlng:LatLng) to change the center of marker by this way you can change the position of your marker runtime. and for storing last locations you can use a database for it and update it as according to your requirement.

Neji
  • 6,591
  • 5
  • 43
  • 66
0

Add this javascript function to your code ,

 $(function () {
        setTimeout(function () { $('#map_canvas').load(initialize); }, 50000);
    })