所以返回的值,我想不通,爲什麼這是行不通的:無法檢索JSON由MapQuest的API
$.getJSON('http://www.mapquestapi.com/geocoding/v1/reverse?key=KEY&callback=renderReverse&json&location=' + lat + ',' + longi, function(geo) {
$('#location').html(geo.response.results[0].locations[0].adminArea4);
});
返回的JSON是:
{
"results": [
{
"locations": [
{
"latLng": {
"lng": -1,
"lat": 51
},
"adminArea4": "Hamp",
"adminArea5Type": "City",
"adminArea4Type": "County",
"adminArea5": "Ba and De",
"street": "Teal Crescent",
"adminArea1": "GB",
"adminArea3": "England",
"type": "s",
"displayLatLng": {
"lng": -1.145731,
"lat": 51.240441
},
"linkId": 0,
"postalCode": "RG3",
"sideOfStreet": "N",
"dragPoint": false,
"adminArea1Type": "Country",
"geocodeQuality": "ADDRESS",
"geocodeQualityCode": "L1AAA",
"mapUrl": "http://www.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luubnu0yn5,7g=o5-9072ur&type=map&size=225,160&pois=purple-1,51.2401563,-1.1463337,0,0|¢er=51,-17&zoom=15&rand=-859825484",
"adminArea3Type": "State"
}
],
"providedLocation": {
"latLng": {
"lng": -1.146334,
"lat": 51.240156
}
}
}
],
"options": {
"ignoreLatLngInput": false,
"maxResults": -1,
"thumbMaps": true
},
"info": {
"copyright": {
"text": "© 2013 MapQuest, Inc.",
"imageUrl": "http://api.mqcdn.com/res/mqlogo.gif",
"imageAltText": "© 2013 MapQuest, Inc."
},
"statuscode": 0,
"messages": []
}
}
我猜測這是因爲我得到geo.response.results
位錯了!
幫助將不勝感激。
請更改您的問題標題! –
你確定'$('#location')。html('甚至在執行嗎?我希望這會失敗,因爲你告訴服務把它作爲一個特定的回調用'&callback = renderReverse'返回,除非服務忽略它並返回CORS頭文件 –
@KevinB:我改變了&callback = renderReverse爲&callback =? 現在正在工作,我從mapquests的api文檔中抓取了這個url,並忘記它是用於JavaScript的!非常感謝! – GeorgeTaylor