Javascript jQuery JSON解析谷歌地图问题
我正在尝试使用以下代码从google maps获取json响应:Javascript jQuery JSON解析谷歌地图问题,javascript,jquery,json,api,google-maps,Javascript,Jquery,Json,Api,Google Maps,我正在尝试使用以下代码从google maps获取json响应: var address = 'Sydney,NSW'; $.ajax({ type: "GET", url: "http://maps.googleapis.com/maps/api/geocode/json?sensor=false", dataType: "jsonp", data: ({"address":address}), success: function(json)
var address = 'Sydney,NSW';
$.ajax({
type: "GET",
url: "http://maps.googleapis.com/maps/api/geocode/json?sensor=false",
dataType: "jsonp",
data: ({"address":address}),
success: function(json){
if (json.status == "OK") {
alert(":)");
} else {
alert('wrong!');
}
}
});
它工作得很好,但是
因此,我得到了
未捕获的语法错误:意外标记:
铬和
错误:在FireFox中找不到元素
返回的JSON似乎有问题,但看起来不错:
{
"status": "OK",
"results": [ {
"types": [ "locality", "political" ],
"formatted_address": "Sydney New South Wales, Australia",
"address_components": [ {
"long_name": "Sydney",
"short_name": "Sydney",
"types": [ "locality", "political" ]
}, {
"long_name": "New South Wales",
"short_name": "New South Wales",
"types": [ "administrative_area_level_1", "political" ]
}, {
"long_name": "Australia",
"short_name": "AU",
"types": [ "country", "political" ]
} ],
"geometry": {
"location": {
"lat": -33.8689009,
"lng": 151.2070914
},
"location_type": "APPROXIMATE",
"viewport": {
"southwest": {
"lat": -34.1648540,
"lng": 150.6948538
},
"northeast": {
"lat": -33.5719182,
"lng": 151.7193290
}
},
"bounds": {
"southwest": {
"lat": -34.1692489,
"lng": 150.5022290
},
"northeast": {
"lat": -33.4245980,
"lng": 151.3426361
}
}
}
}]
}返回必须是jsonp而不是json(json应该包装到函数调用中) 尝试使用GM2(看起来GM3不支持jsonp) }
}); 返回必须是jsonp而不是json(json应该包装到函数调用中) 尝试使用GM2(看起来GM3不支持jsonp) }
}); 看起来,没有办法通过jsonp实现这一点,也没有办法通过jsonp实现这一点
$.ajax({
type: "GET",
url: "http://maps.google.com/maps/geo?sensor=false&output=json&"+$.param({"q":address}),
dataType: "jsonp",
success: function(json){
if (json.Status.code == "200") {
alert(":)");
} else {
alert('wrong!');
}