暂时在这个问题上摸不着头脑,寻找答案却无济于事。任何帮助都会非常感激,因为我对js很新。
以下功能在我的代码中以2个点被调用,具有相同的邮政编码。第一次运行时,它成功(警告'Geocode SUCCESSFUL'),但第二次它什么都不做,没有警报。我知道它正在进入第一个警报“Postcode = SO16 6AB,UK& sensor = false”两次都会发生。
有什么想法吗?
function geolocatePostcode(postcode, coordinates){
var geocoder = new google.maps.Geocoder();
var address = postcode + ', UK&sensor=false';
alert("Postcode = " + address);
geocoder.geocode(
{'address': address},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
alert("Geocode SUCCESSFUL");
coordinates([ results[0].geometry.location.lat(), results[0].geometry.location.lng() ]);
}
else {
alert("Geocode was not successful for the following reason: " + status);
coordinates(false);
}
}
);
}
调用函数(当动作'checkout'时,当动作'更新'时,它会一次调用'更新')...
function saveAction(action){
console.log("SaveAction called!");
switch(action) {
case 'add':
case 'checkout':
var url = '/properties/add-property';
console.log("SaveAction 'add' switched!");
break;
case 'update' :
var url = '/properties/edit-property';
console.log("SaveAction 'update' switched!");
break;
case 'continue':
var url = '/properties/checkout';
console.log("SaveAction 'checkout' switched!");
break;
default:
console.log("Invalid saveAction() paramter specified in property.js");
}
if (action != 'continue'){
geolocatePostcode(postcode.val(), function(coordinates){
if (coordinates[0]) {
bValid = true;
lat = coordinates[0];
lon = coordinates[1];
console.log("valid postcode");
}
else {
alert('Your postcode appears to be invalid. Please check the postcode and try again.');
console.log("invalid postcode");
return false;
}