我的谷歌地图 api 脚本出了点问题 [英] Something happened to my google map api script
问题描述
在完成"Web 部件后,我一直在做我的项目的移动部分.我正在使用谷歌地图 API.我编写了以下代码:
I've been doing mobile part of my project after "completing" the web part. I'm using google map api. I have coded following:
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
(PPM usuwa znacznik)");
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
google.maps.event.addListener(markerZad, 'click', function() {
alert("Nowe zadanie:
"+ address + "
"+"Wybierz pracownika
(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] 存在问题.请问有什么建议吗?
Let's leave behind the level of this code. I'm sure it's a bad one. But the thing is...it used to work for me like few days ago. Now it doesn't. And yes, I haven't touched it since then... I figured out myself, that the problem causes "results". I get status==OK, then it places a marker in a correct spot, and then...nothing happens. I mean my inputs in html file don't get their values changed and +listeners aren't working. When I changed "results[0]." etc to simple string, it worked, that's why I think that there's a problem with results[0]. Any suggestions please?
推荐答案
不要访问未记录的属性,例如results[0].geometry.location.nb
.这些属性的名称可能(并且将会)改变.要访问这些属性的值,请使用记录的方法,例如lat()
访问 LatLng
实例的纬度:
Don't access undocumented properties like e.g. results[0].geometry.location.nb
. The names of these properties may(and will) change. To access the values of these properties use the documented methods, e.g. lat()
to access the latitude of a LatLng
-instance:
document.getElementById('latitude').value
= results[0].geometry.location.lat().toPrecision(9);
这篇关于我的谷歌地图 api 脚本出了点问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!