0

I have the following code, that get's a user position on Android, and creates or (should) update a marker on the Map

var myPos = null;

function locSuccess(position) {

 var newPoint = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

 if(myPos == null) {
     myPos = new google.maps.Marker({
        'id':'myPos',
        'position':newPoint,
        'icon' : 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png'
     });
     $('#map_canvas').gmap('addMarker', myPos);
 } else {
    myPos.setPosition(newPoint); 
 }

 $('#map_canvas').gmap('get', 'map').panTo(newPoint);
 $('#map_canvas').gmap('refresh');  
}

The creation of the new marker works fine, the Panning to the new point when the position is updated also works fine, just the marker doesn't change it's position

Any ideas ?

Thanks in advance

sahmed24
  • 358
  • 2
  • 3
  • 13

1 Answers1

1

Keeping the position in a variable like I had doesn't work, I had to assign the variable to the marker in the markers Array like this

var myPos = $('#map_canvas').gmap('get', 'markers')['myPos']; 

if(!myPos) {
    //Create a new marker
    $('#map_canvas').gmap('addMarker', {
        'id':'myPos',
        'position':newPoint,
        'icon' : 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png'
    });
    $('#map_canvas').gmap('option', 'zoom', 12);
} else {
    //If there is already a marker, update the position
    myPos.setPosition(newPoint); 
}
sahmed24
  • 358
  • 2
  • 3
  • 13