Wern Ancheta
Wern Ancheta

Reputation: 23317

Is there a way to get the coordinates of a marker in Google Maps?

I'm trying to get my hands dirty on Google Maps API v3. But now I'm stuck with figuring out how to get the coordinates of a certain marker?

<script>

    var homeLatlng = new google.maps.LatLng(16.61096000671, 120.31346130371);
    var homeMarker = new google.maps.Marker({
        position: homeLatlng,
        map: map
    });

    var myOptions = {
        center: new google.maps.LatLng(16.61096000671, 120.31346130371),
        zoom: 10,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

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

    //I know that I'm the one who set the coordinates for this,
    // but how do I fetch it back?

    $('#plot').click(function(){
        homeMarker.setMap(map);
    });

</script>

Upvotes: 1

Views: 1053

Answers (1)

Chad Killingsworth
Chad Killingsworth

Reputation: 14411

homeMarker.getPosition(); //returns a google.maps.LatLng object

Upvotes: 4

Related Questions