【发布时间】:2011-04-14 06:58:28
【问题描述】:
我无法从 google maps api 获取地理位置信息
代码很简单
$.ajax({
type: "GET",
cache: false,
url: "http://maps.googleapis.com/maps/api/geocode/json",
dataType: "jsonp",
data: {
address: "Ljubljana " + "Slovenia",
sensor: "false"
},
jsonpCallback:'json_response',
success: function(data) {
top.console.debug(data);
$('#location_setter').dialog('close');
},
error: function() {
alert("Error.");
}
});
function json_response(data){
alert("works");
}
我总是收到错误消息。 我也直接试过(我在某处读到应该在最后设置回调......
$.ajax({
type: "GET",
cache: true,
url: "http://maps.googleapis.com/maps/api/geocode/json?address=Ljubljana Slovenia&sensor=false",
dataType: "jsonp",
jsonpCallback:'json_response',
success: function(data) {
top.console.debug(data);
$('#location_setter').dialog('close');
},
error: function() {
alert("Error.");
}
});
请求的 url 格式正确:
它给了我正确的 json
请指教!
您可以在http://jsfiddle.net/PNad9/“玩”它
【问题讨论】: