谷歌地图地理编码未定义
我有这个在加载时启动的代码
// 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.');
}
});
}
,但出现以下错误
geocoder is not defined
http://localhost/bakasura1/js/modal.js
Line 74
I have this code which is initated on load
// 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.');
}
});
}
i get the following error
geocoder is not defined
http://localhost/bakasura1/js/modal.js
Line 74
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯...呃...它说什么。您说的是
geocoder.geocode(...)
,但您实际上并未定义任何名为geocoder
的变量。你是否忘记了:Well... er... what it says. You're saying
geocoder.geocode(...)
, but you've not actually defined any variable calledgeocoder
. Did you forget:你在某处有这条线吗?我在提供的代码中没有看到它。
Do you have this line somewhere? I don't see it in the code provided.
还要确保您
已经运行了 javascript 代码。
这就是让我陷入困境的原因。
Also make sure you have
prior to running the javascript code.
That's what messed me up.