gpt4 book ai didi

javascript - Uncaught ReferenceError : latLng is not defined

转载 作者:行者123 更新时间:2023-12-02 18:40:11 24 4
gpt4 key购买 nike

我的谷歌地图,我试图显示标记位置的纬度和经度。我收到以下错误“ Uncaught ReferenceError :latLng未定义”。我应该在此处包含什么.

我的代码如下

js:

var map;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-29.3456, 151.4346),
zoom: 2,
scrollwheel: false,
disableDefaultUI: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
}

function addMarker() {
marker = new google.maps.Marker({
position: new google.maps.LatLng(-29.3456, 151.4346),
map: map,
draggable: true
});
}
//show the marker position

function updateMarkerPosition(latLng) {
document.getElementById('info').innerHTML = [
latLng.lat(),
latLng.lng()
].join(', ');
}
updateMarkerPosition(latLng);
geocodePosition(latLng);

html:

<div id="info"></div>

谢谢

最佳答案

我想你一定是忘记初始化你的 map 了。我已经把你的 fiddle 修好了。 http://jsfiddle.net/harendra/Lt2rp/1/

  var map;
initialize();
var curlatLng=new google.maps.LatLng(-29.3456, 151.4346)
updateMarkerPosition(curlatLng);


function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-29.3456, 151.4346),
zoom: 2,
scrollwheel: false,
disableDefaultUI: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
}

function addMarker() {
marker = new google.maps.Marker({
position: new google.maps.LatLng(-29.3456, 151.4346),
map: map,
draggable: true
});
}

function updateMarkerPosition(latLng) {
document.getElementById('info').innerHTML = [
latLng.lat(),
latLng.lng()
].join(', ');
}

关于javascript - Uncaught ReferenceError : latLng is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16915542/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com