我要做的是从导入的邮政编码中获取纬度和经度。只要我只坚持一个输入(第一个或第二个单独),它就可以正常工作。一旦我尝试使用它们,我就无法让它工作。我正在使用 onchange 事件..
请看一下表格:
<form name="latlon" action="test2a.php" method='post' onchange="return usePointFromPostcode(document.getElementById('postcode').value) && usePointFromPostcode1(document.getElementById('postcode1').value) ">
<input id="postcode" type="text" size="10" /><br>
<input id="postcode1" type="text" size="10"/><br>
Latitude:<input name="lat" type="text" id="lat" size="10"/><br />
Longitude:<input name="lon" type="text" id="lon" size="10"/><br><br>
Latitude:<input name="lat1" type="text" id="lat1" size="10"/><br />
Longitude:<input name="lon1" type="text" id="lon1" size="10"/>
<input type="submit" value="Get Lat / Lon"/>
</form>
在 JavaScript 中,这是我用来获取纬度和经度的:
function usePointFromPostcode(postcode, callbackFunction) {
localSearch.setSearchCompleteCallback(null,
function () {
if (localSearch.results[0]) {
var resultLat = localSearch.results[0].lat;
var resultLng = localSearch.results[0].lng;
var point = new GLatLng(resultLat, resultLng);
document.forms['latlon'].lat.value = resultLat;
document.forms['latlon'].lon.value = resultLng;
callbackFunction(point);
} else {
alert("Postcode not found!");
}
});
localSearch.execute(postcode + ", UK");
}
function usePointFromPostcode1(postcode1, callbackFunction) {
localSearch.setSearchCompleteCallback(null,
function () {
if (localSearch.results[0]) {
var resultLat = localSearch.results[0].lat;
var resultLng = localSearch.results[0].lng;
var point = new GLatLng(resultLat, resultLng);
document.forms['latlon'].lat1.value = resultLat;
document.forms['latlon'].lon1.value = resultLng;
callbackFunction(point);
} else {
alert("Postcode not found!");
}
});
localSearch.execute(postcode1 + ", UK");
}
我完全被困在这里。我究竟做错了什么?将不胜感激任何帮助,并提前感谢您。