I'm building a web app that calls the mapquest Geocoding API to grab the users lat-long position, and then make a second call to another API to return another set of data. The main issue I am having is when I call the mapquest Geocode API the user can enter any string of characters or made up locations and it returns JSON with data. I need to find a way to prevent this by ensuring the user enters an actual location. Here is the mapquest Geocode API https://developer.mapquest.com/documentation/geocoding-api/address/get/
and I believe my answer lies in here but I am not sure how I would use these to validate the location https://developer.mapquest.com/documentation/geocoding-api/quality-codes/
I've tried setting up a few if statements looking for an X in any of the values for responseJson.results[0].locations[0].geocodeQualityCode but that still kicked back valid results
this is an example of an acceptable entry that the API returns
{
"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"
}
]
}
]
}