【发布时间】:2011-09-27 07:45:14
【问题描述】:
我正在尝试使用谷歌地图的 REST api 将输入的地址转换为坐标。为此,我使用 jQuery 的 getJSON 函数,因为它使用原生 JSONP 调用。
虽然它不起作用,但它只是没有成功,所以永远不会调用警报。
$("#makeCords").click(function(){
straat = $('#straat').val();
stad = $('#Stad').val();
land = $('#Country').val();
if(straat == "" || stad == "" || land == ""){
alert("Onvoldoende gegevens! Vul straat, stad en land aan voor het gebruik van de ´bereken coordinaten´ functie.");
}else{
$.getJSON("http://maps.google.com/maps/api/geocode/json?callback=?",
{
adress: straat +", " + stad +", " + land,
sensor: "false"
},
function(data) {
alert(data);
});
}
});
【问题讨论】:
-
如果您使用 URL
http://maps.google.com/maps/api/geocode/json会发生什么? -
aaddress 确实是一种类型。但是,谷歌也会以 json 格式响应错误。所以警报仍然应该被执行。不是。
标签: javascript jquery google-maps jsonp getjson