-1

我可以在地图上设置图钉,但无法检索该点的纬度和经度。这是我的代码。有人能帮忙吗?

谢谢

 function codeaddress() {
    var geocoder;
    //map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    geocoder = new google.maps.Geocoder();

    var address = document.getElementById("address").value;

    geocoder.geocode({ 'address': address }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {


            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                animation: google.maps.Animation.BOUNCE,
                flat: false,
                map: map,
                position: results[0].geometry.location

            });

            var latt = document.getElementById("latitude");
            latt.value = results[0].geometry.location.getlatitude();
            alert(latt.value);

        } else {
            alert("Geocode was not successful for the following reason: " + status);
        }
    });

}
4

1 回答 1

1

尝试使用.lat()而不是.getLatitude().

请参阅有关 LatLng 类的 API:https ://developers.google.com/maps/documentation/javascript/reference#LatLng

于 2013-03-08T11:22:18.037 回答