tôi có mã này được initated trên tảiGoogle Maps Mã hóa địa lý Undefined
// Display the map
function map_it() {
var myLatlng = new google.maps.LatLng(13.005621, 77.577531);
var myOptions = {
zoom: zoomLevel,
center: myLatlng,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
}
}
map = new google.maps.Map(document.getElementById("map-it"), myOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
draggable: true
});
google.maps.event.addListener(marker, 'dragend', function (event) {
document.getElementById('mapLat').value = marker.getPosition().lat();
document.getElementById('mapLng').value = marker.getPosition().lng();
geocodePosition(marker.getPosition());
});
}
function geocodePosition(pos) {
geocoder.geocode({
latLng: pos
}, function (responses) {
if (responses && responses.length > 0) {
updateMarkerAddress(responses[0].formatted_address);
alert(responses[0].formatted_address);
} else {
updateMarkerAddress('Cannot determine address at this location.');
}
});
}
tôi nhận được lỗi sau
geocoder is not defined
http://localhost/bakasura1/js/modal.js
Line 74
ouch: D đã nhận được: D cảm ơn –
Lỗi lầm tương tự xảy ra với tôi. Cảm ơn – RredCat
Đây là câu trả lời cho trường hợp cụ thể này, nhưng nên mở một câu hỏi trùng lặp mới chỉ vì giải pháp này không áp dụng? Tôi có dòng đó ở đầu mã, và hàm ẩn danh của tôi gọi nó (không thực thi trước dòng trên, nhưng onclick) tìm thấy nó không xác định. Tôi đã thử nghiệm bộ mã hóa địa lý với console.log bên trong mọi chức năng trong chuỗi chức năng này, và KHÔNG ai trong số họ có thể tìm thấy nó. Nó giống như có "var geocoder = ..." ở cấp tài liệu là không đủ. – sergio