Cómo cambiar la posición de marcador de una función javascript?


Tengo que cambiar la posición de un marcador en Google Map desde una función javascript. ¿Cómo puedo lograrlo?

Author: Kara, 2011-04-28

3 answers

Puede utilizar la función setPosition de la clase marker

function changeMarkerPosition(marker) {
    var latlng = new google.maps.LatLng(-24.397, 140.644);
    marker.setPosition(latlng);
}
 102
Author: solidrevolution,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-01 18:32:34

En primer lugar, debe almacenar el marcador en una matriz cuando lo cree para que pueda tener acceso a él después.
A continuación, cambie la posición con marker.setPosition() como se menciona solidrevolution.

 0
Author: Argiropoulos Stavros,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-29 21:11:09

Prueba esto:

var x = document.getElementById("demo");
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}
function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude +
        "<br>Longitude: " + position.coords.longitude;
}
 -6
Author: satish kumar tak,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-27 13:15:00