Tôi đang cố gắng để có được một vĩ độ và kinh độ theo địa chỉ với đoạn mã sau:Google Maps API - geocode() không trả lại lat và dài
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
geocoder = new google.maps.Geocoder();
var address = "HaYarkon 100 TelAviv Israel";
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
{
TelAviv = new google.maps.LatLng(results[0].geometry.location.latitude,results[0].geometry.location.longitude);
}
});
var myOptions = {
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: TelAviv
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
}
Vấn đề là kết quả [0]. geomety.location.latitude và kinh độ là undefinde.
Những gì tôi nhìn thấy trong các kết quả trong giao diện điều khiển là tiếp theo:
location: O
$a: 51.5414691
ab: -0.11492010000006303
Tại sao nó hiển thị $ a và ab thay vì vĩ độ và kinh độ
Tuyệt vời, thx! – Alon
Và trong ví dụ của bạn, bạn không phải tạo một 'google.maps.LatLng' mới; 'kết quả [0] .geometry.location' _is_ a google.maps.LatLng'. –
@Sean Mickey, Có lẽ bạn có thể giúp đỡ với một vấn đề khác, tôi dường như không thể lưu dữ liệu đó vào một biến trong kịch bản của tôi. Làm thế nào tôi có thể lưu nó và sử dụng nó? – Alon