Update Marker On Google Map Every X Seconds
I am trying to update marker on google map for every x seconds based on the data returned from a AJAX call. The Ajax function is called for every x seconds but the marker is not sh
Solution 1:
Assuming that the request runs as expected and returns a valid JSON:
var latlng = new google.maps.LatLng(data['gps_position_longitude'], data['gps_position_latitude']);
A google.maps.LatLng
expects the arguments to be in the order latitude, longitude
, not longitude,latitude
.
Furthermore: instead of creating new markers on each request you better create a single marker and use setPosition()
to update the position.
Additionally: to ensure that the marker is visible inside the viewport also set the center of the map to latlng
Solution 2:
Try use javascript to alert a message with the new marker's position to see if it really gets updated in the background. If it dose, then its to do with refreshing the dom or something.
Post a Comment for "Update Marker On Google Map Every X Seconds"