有没有办法在Google地图中获取标记的坐标?

时间:2012-05-05 13:13:28

标签: google-maps-api-3 google-maps-markers

我正试图在Google Maps API v3上弄脏自己的手。但现在我不知道如何获得某个标记的坐标?

<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>

1 个答案:

答案 0 :(得分:4)

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