在“完成”网络部分后,我一直在做项目的移动部分。我正在使用谷歌地图API。我编写了以下代码:
function codeAddress() {
var image = 'images/tickmark1.png';
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 markerZad = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
title: "NEW TASK",
icon: image
});
document.getElementById('latitude').value =results[0].geometry.location.nb.toPrecision(9);
document.getElementById('longitude').value=results[0].geometry.location.ob.toPrecision(9);
document.getElementById('adrs').value=document.getElementById('address').value;
document.getElementById('latit').value =results[0].geometry.location.nb.toPrecision(9);
document.getElementById('longit').value=results[0].geometry.location.ob.toPrecision(9);
alert("Ustalono wspolrzedne nowego zadania. Wybierz pracownika \n (PPM usuwa znacznik)");
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
google.maps.event.addListener(markerZad, 'click', function() {
alert("Nowe zadanie: \n"+ address + "\n"+"Wybierz pracownika \n (PPM usuwa znacznik)");
map.setZoom(14);
map.setCenter(this.getPosition());
});
google.maps.event.addListener(markerZad, 'rightclick', function() {
markerZad.setMap(null);
document.getElementById('latitude').value =0;
document.getElementById('longitude').value=0;
document.getElementById('adrs').value=0;
document.getElementById('latit').value =0;
document.getElementById('longit').value=0;
document.getElementById('ajdideva').value="X";
document.getElementById('iddev').value=0;
document.getElementById('baton').disabled=true;
alert("Usunieto znacznik. Wpisz inny adres.");
});
});
}
让我们抛开这段代码的级别。我确信这是一件坏事。但问题是......它曾经对我有用,就像几天前一样。现在不行了。是的,从那以后我就没有碰过它......我自己发现,问题导致了“结果”。我得到 status==OK,然后它将标记放置在正确的位置,然后......什么也没有发生。我的意思是我在 html 文件中的输入的值没有改变,并且 +listeners 不起作用。当我更改“结果[0]”时。等到简单的字符串,它有效,这就是为什么我认为结果[0]有问题。请问有什么建议吗?
最佳答案
不要访问未记录的属性,例如结果[0].geometry.location.nb
。这些属性的名称可能(并且将会)更改。要访问这些属性的值,请使用记录的方法,例如lat()
访问 LatLng
实例的纬度:
document.getElementById('latitude').value
= results[0].geometry.location.lat().toPrecision(9);
关于javascript - 我的 google map api 脚本出了问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21066167/