Closed barriault closed 9 years ago
Just some followup information, I've used the Unexpected Responses From Geocoding Services suggestion to get a URL that uses my API key to try in my browser. Here is the returned JSON:
{"info":{"statuscode":0,"copyright":{"text":"\u00A9 2015 MapQuest, Inc.","imageUrl":"http://api.mqcdn.com/res/mqlogo.gif","imageAltText":"\u00A9 2015 MapQuest, Inc."},"messages":[]},"options":{"maxResults":-1,"thumbMaps":true,"ignoreLatLngInput":false},"results":[{"providedLocation":{"location":"8640 N. Dixson Avenue, Kansas City, MO"},"locations":[{"street":"8640 N Dixson Ave","adminArea6":"","adminArea6Type":"Neighborhood","adminArea5":"Kansas City","adminArea5Type":"City","adminArea4":"Platte","adminArea4Type":"County","adminArea3":"MO","adminArea3Type":"State","adminArea1":"US","adminArea1Type":"Country","postalCode":"64153-1936","geocodeQualityCode":"L1AAA","geocodeQuality":"ADDRESS","dragPoint":false,"sideOfStreet":"L","linkId":"24261496i34268650r62781602","unknownInput":"","type":"s","latLng":{"lat":39.251268,"lng":-94.665313},"displayLatLng":{"lat":39.251268,"lng":-94.665313},"mapUrl":"http://www.mapquestapi.com/staticmap/v4/getmap?key=key_removed&type=map&size=225,160&pois=purple-1,39.251268,-94.665313,0,0,|¢er=39.251268,-94.665313&zoom=15&rand=1207180863"}]}]}
This shows the API appears to be working, but for some reason the JSON response can't be parsed? Any ideas?
"Things were working fine until recently" is a key piece of information here. Did any code change in your app? Did anything in the environment change? Is it possible you're hitting the geocoding API's quota? Or that there's some other error being returned when the request is made from the gem? Note that a common reason for the can't-be-parsed message is that an API has returned an error that is not a JSON document.
Well, absolutely nothing in the code changed which is why things proved frustrating. However, I did find that someone changed the list of allowed referrers for the license key. Nobody has fessed up to it, but it certainly caused me several days of pain and grief.
I'm currently having this issue.
Location 1: (works on API and Gem)
address = "4713 westwood st, simi valley, CA, 93063"
Results
response = Geocoder::Lookup.get(:mapquest).send(:fetch_raw_data, Geocoder::Query.new(address))
response: [#<Geocoder::Result::Nominatim:0xbc41ba4c @data={"place_id"=>"206473670", "licence"=>"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "osm_type"=>"way", "osm_id"=>"10732837", "boundingbox"=>["34.301242895386", "34.301342895386", "-118.7024533509", "-118.7023533509"], "lat"=>"34.3012928953856", "lon"=>"-118.702403350896", "display_name"=>"4713, Westwood Street, Simi Valley, Ventura County, California, 93063, USA", "class"=>"place", "type"=>"house", "importance"=>0.721, "address"=>{"house_number"=>"4713", "road"=>"Westwood Street", "city"=>"Simi Valley", "county"=>"Ventura County", "state"=>"California", "postcode"=>"93063", "country"=>"USA", "country_code"=>"us"}}, @cache_hit=nil>]
Location 2: (works on API but not on Gem)
address = "9566 topanga Cyn Blvd, Chatsworth, CA, 91311"
Results
response = Geocoder::Lookup.get(:mapquest).send(:fetch_raw_data, Geocoder::Query.new(address))
[]
If i change location 2 to have 'Canyon' instead of 'Cyn' it works on both the api and gem.
@MrGurns this is just how the API responds to that query, looks like the gem is working as expected.
The API responds successfully with the same result whether i specify 'Cyn' or 'Canyon', however if i specify 'Cyn' the gem responds with empty array.
'Cyn':
response = {
"info":
{
"statuscode": 0,
"copyright":
{
"text": "\\u00A9 2018 MapQuest, Inc.",
"imageUrl": "http://api.mqcdn.com/res/mqlogo.gif",
"imageAltText": "\\u00A9 2018 MapQuest, Inc."
},
"messages": []
},
"options":
{
"maxResults": -1,
"thumbMaps": true,
"ignoreLatLngInput": false
},
"results": [
{
"providedLocation":
{
"location": "9566 topanga Cyn Blvd, Chatsworth, CA, 91311"
},
"locations": [
{
"street": "9566 Topanga Canyon Blvd",
"adminArea6": "",
"adminArea6Type": "Neighborhood",
"adminArea5": "Chatsworth",
"adminArea5Type": "City",
"adminArea4": "Los Angeles",
"adminArea4Type": "County",
"adminArea3": "CA",
"adminArea3Type": "State",
"adminArea1": "US",
"adminArea1Type": "Country",
"postalCode": "91311-4011",
"geocodeQualityCode": "L1AAA",
"geocodeQuality": "ADDRESS",
"dragPoint": false,
"sideOfStreet": "R",
"linkId": "rnr8950840|i10690273",
"unknownInput": "",
"type": "s",
"latLng":
{
"lat": 34.244443,
"lng": -118.606837
},
"displayLatLng":
{
"lat": 34.244492,
"lng": -118.606643
},
"mapUrl": "http://www.mapquestapi.com/staticmap/v5/map?key=[omitted]\u0026type=map\u0026size=225,160\u0026locations=34.244443,-118.606837|marker-sm-50318A-1\u0026scalebar=true\u0026zoom=15\u0026rand=-1008621523"
}]
}]
}
result = []
'Canyon'
response = {
"info":
{
"statuscode": 0,
"copyright":
{
"text": "\\u00A9 2018 MapQuest, Inc.",
"imageUrl": "http://api.mqcdn.com/res/mqlogo.gif",
"imageAltText": "\\u00A9 2018 MapQuest, Inc."
},
"messages": []
},
"options":
{
"maxResults": -1,
"thumbMaps": true,
"ignoreLatLngInput": false
},
"results": [
{
"providedLocation":
{
"location": "9566 topanga canyon Blvd, Chatsworth, CA, 91311"
},
"locations": [
{
"street": "9566 Topanga Canyon Blvd",
"adminArea6": "",
"adminArea6Type": "Neighborhood",
"adminArea5": "Chatsworth",
"adminArea5Type": "City",
"adminArea4": "Los Angeles",
"adminArea4Type": "County",
"adminArea3": "CA",
"adminArea3Type": "State",
"adminArea1": "US",
"adminArea1Type": "Country",
"postalCode": "91311-4011",
"geocodeQualityCode": "L1AAA",
"geocodeQuality": "ADDRESS",
"dragPoint": false,
"sideOfStreet": "R",
"linkId": "rnr8950840|i10690273",
"unknownInput": "",
"type": "s",
"latLng":
{
"lat": 34.244443,
"lng": -118.606837
},
"displayLatLng":
{
"lat": 34.244492,
"lng": -118.606643
},
"mapUrl": "http://www.mapquestapi.com/staticmap/v5/map?key=[omitted]\u0026type=map\u0026size=225,160\u0026locations=34.244443,-118.606837|marker-sm-50318A-1\u0026scalebar=true\u0026zoom=15\u0026rand=-1227182062"
}]
}]
}
result = [#<Geocoder::Result::Nominatim:0xbc78d9a0 @data={"place_id"=>"204549165", "licence"=>"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "osm_type"=>"way", "osm_id"=>"401067794", "boundingbox"=>["34.244358143751", "34.244458143752", "-118.60714067481", "-118.60704067481"], "lat"=>"34.2444081437515", "lon"=>"-118.607090674815", "display_name"=>"9566, Topanga Canyon Boulevard, Chatsworth, Los Angeles, Los Angeles County, California, 91311, USA", "class"=>"place", "type"=>"house", "importance"=>0.6309999999999999, "address"=>{"house_number"=>"9566", "road"=>"Topanga Canyon Boulevard", "suburb"=>"Chatsworth", "city"=>"Los Angeles", "county"=>"Los Angeles County", "state"=>"California", "postcode"=>"91311", "country"=>"USA", "country_code"=>"us"}}, @cache_hit=nil>]
I think MapQuest may have changed their API recently. Geocoder.search("McCarren Park, Brooklyn, NY") is returning a 'Geocoding API's response was not valid JSON.' error. Things were working fine until recently.