我正在构建一个 Web 应用程序,它调用 mapquest 地理编码 API 来获取用户的经纬度位置,然后再次调用另一个 API 以返回另一组数据。我遇到的主要问题是当我调用 mapquest Geocode API 时,用户可以输入任何字符串或组成位置,它会返回带有数据的 JSON。我需要找到一种方法来确保用户输入实际位置来防止这种情况发生。这是 mapquest 地理编码 API https://developer.mapquest.com/documentation/geocoding-api/address/get/
我相信我的答案就在这里,但我不确定如何使用这些来验证位置https://developer.mapquest.com/documentation/geocoding-api/quality-codes/
我已经尝试设置一些 if 语句在 responseJson.results[0].locations[0].geocodeQualityCode 的任何值中查找 X 但这仍然会退回有效结果
这是 API 返回的可接受条目的示例
{
"info": {
"statuscode": 0,
"copyright": {
"text": "© 2019 MapQuest, Inc.",
"imageUrl": "http://api.mqcdn.com/res/mqlogo.gif",
"imageAltText": "© 2019 MapQuest, Inc."
},
"messages": []
},
"options": {
"maxResults": -1,
"thumbMaps": true,
"ignoreLatLngInput": false
},
"results": [
{
"providedLocation": {
"location": "Lawton, ok"
},
"locations": [
{
"street": "",
"adminArea6": "",
"adminArea6Type": "Neighborhood",
"adminArea5": "Lawton",
"adminArea5Type": "City",
"adminArea4": "Comanche County",
"adminArea4Type": "County",
"adminArea3": "OK",
"adminArea3Type": "State",
"adminArea1": "US",
"adminArea1Type": "Country",
"postalCode": "",
"geocodeQualityCode": "A5XAX",
"geocodeQuality": "CITY",
"dragPoint": false,
"sideOfStreet": "N",
"linkId": "282026294",
"unknownInput": "",
"type": "s",
"latLng": {
"lat": 34.606378,
"lng": -98.396817
},
"displayLatLng": {
"lat": 34.606378,
"lng": -98.396817
},
"mapUrl": "http://www.mapquestapi.com/staticmap/v5/map?key=zkn6RGyTDlLGsN8i8RfEmURf2GozTAkL&type=map&size=225,160&locations=34.606378,-98.396817|marker-sm-50318A-1&scalebar=true&zoom=12&rand=197404762"
}
]
}
]
}