gpt4 book ai didi

javascript - 无法从 MapQuest API 返回的 JSON 中检索值

转载 作者:行者123 更新时间:2023-11-30 10:25:41 26 4
gpt4 key购买 nike

所以,我不明白为什么这行不通:

$.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|&center=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 有点错误!

帮助将不胜感激。

最佳答案

返回的 JSON 中没有 response 键。试试这个:

$.getJSON('http://www.mapquestapi.com/geocoding/v1/reverse?key=KEY&callback=renderReverse&json&location=' + lat + ',' + longi, function(geo) {
$('#location').html(geo.results[0].locations[0].adminArea4);
});

关于javascript - 无法从 MapQuest API 返回的 JSON 中检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19662428/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com