1

I'm updating the marker on my google map with new positions constantly from the server. The positions are stored in the variables called Longitude and Latitude. I managed to get the markers moving to the new positions but the map constantly refreshes. What can I do to stop this from happening? I only want the markers to move.

google.maps.visualRefresh = true;   

//in my actual code the coordinates aren't var lat and lon

var myLatlng = new google.maps.LatLng(lat,lon); 
var mapOptions = {
    zoom: 15,
    center: myLatlng,
    mapTypeControl: true,
    mapTypeControlOptions: {
        style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
        position: google.maps.ControlPosition.BOTTOM_CENTER
    },
    panControl: true,
    panControlOptions: {
        position: google.maps.ControlPosition.TOP_RIGHT
    },
    zoomControl: true,
    zoomControlOptions: {
        style: google.maps.ZoomControlStyle.LARGE,
        position: google.maps.ControlPosition.LEFT_CENTER
    },
    scaleControl: true,
    streetViewControl: true,
    streetViewControlOptions: {
        position: google.maps.ControlPosition.LEFT_TOP
    }
}

var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
google.maps.event.trigger(map, 'resize');
var marker = new google.maps.Marker({
  position: myLatlng,
  map: map,
  title: 'Hello World!'
});


var latlng = new google.maps.LatLng(Latitude,Longitude);
marker.setPosition(latlng);
//map.setCenter(latlng);
//covertlisten.remove();
});
}

google.maps.event.addDomListener(window, 'load', initialize);
Mifeet
  • 12,949
  • 5
  • 60
  • 108
Brandon
  • 151
  • 1
  • 11

1 Answers1

0

Get rid of map.setCenter(latlng);

javisrk
  • 582
  • 4
  • 19
  • that didn't really work. I updated my entire code above. – Brandon Aug 28 '14 at 19:31
  • Where does the map refresh to? – javisrk Aug 28 '14 at 19:44
  • By "that didn't really work" what do you mean? Is it still refreshing? Is it doing something else? Has anything changed at all? You need to be more clear please. – OneHoopyFrood Aug 28 '14 at 19:44
  • Sorry, I mean I don't think I managed to get it to stop refreshing entirely. It seems like some kind of refreshing may be happening however it's not as bad as before. Also, now I can not keep up with the marker at all. – Brandon Aug 28 '14 at 19:47
  • What are the specifics of the refresh? Does the map reload, does the marker set itself twice? What do you mean by not keeping up with the marker? – javisrk Aug 28 '14 at 20:27
  • Well initially, when there was a refresh, the page would appear blank for a much longer period of time than when I got rid of the map.setCenter(). Once I removed map.setCenter();, there was still something that appeared as if it were a page refresh however it was very quick and not as bad. The second issue that came from removing map.setCenter was that the marker would go off screen of course. So by saying "keep up with the marker" I mean, follow the marker's position as I was able to with map.setCenter yet I would like to do so without page refreshes – Brandon Aug 28 '14 at 21:14