JSON status code 610 - google-maps

I was obtaining the street, city and country details by passing the latitde and longitude values to the following URL: http://maps.google.com/maps/geo?q="+la+","+lo;. However, this has suddenly stopped working as I now get a returned status code 610 instead of 200. I googled and I came across the fact that Google has deprecated the older version with version V3 and the recommended use is to update to this version. The new URL will be something like this;
http://maps.googleapis.com/maps/api/geocode/json?latlng=25.34041,-55.489864&sensor=false
However, I am completely at lost how to use this? What is the Google API Key? Where should I obtain this from. Earlier I was using the above mentioned URL and imported the following into my project:
import org.json.me.JSONArray;
import org.json.me.JSONObject;
Please help how to proceed with this?

You are requesting a correct URL but your latlong values may be invalid.
I request URL:
http://maps.googleapis.com/maps/api/geocode/json?latlng=25.34041,-55.489864&sensor=false
Results.
{
"results" : [],
"status" : "ZERO_RESULTS"
}
Requested with differnt latlong but same URL:
http://maps.googleapis.com/maps/api/geocode/xml?latlng=51.962146,7.602304&sensor=false"
{
"results" : [
{
"address_components" : [
{
"long_name" : "Rishon-Le-Zion-Ring",
"short_name" : "K6",
"types" : [ "route" ]
},
{
"long_name" : "Münster",
"short_name" : "Münster",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Münster",
"short_name" : "Münster",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "North Rhine-Westphalia",
"short_name" : "NRW",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Germany",
"short_name" : "DE",
"types" : [ "country", "political" ]
},
{
"long_name" : "48149",
"short_name" : "48149",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Rishon-Le-Zion-Ring, 48149 Münster, Germany",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 51.96354080,
"lng" : 7.602404200000001
},
"southwest" : {
"lat" : 51.96109890,
"lng" : 7.601790299999998
}
},
"location" : {
"lat" : 51.96233620,
"lng" : 7.602270099999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 51.96366883029150,
"lng" : 7.603446230291501
},
"southwest" : {
"lat" : 51.96097086970850,
"lng" : 7.600748269708497
}
}
},
"types" : [ "route" ]
},
{
"address_components" : [
{
"long_name" : "48149",
"short_name" : "48149",
"types" : [ "postal_code" ]
},
{
"long_name" : "Münster",
"short_name" : "Münster",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Münster",
"short_name" : "Münster",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Münster",
"short_name" : "Münster",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "North Rhine-Westphalia",
"short_name" : "NRW",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Germany",
"short_name" : "DE",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "48149 Münster, Germany",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 51.9846220,
"lng" : 7.6245910
},
"southwest" : {
"lat" : 51.9381030,
"lng" : 7.57505310
}
},
"location" : {
"lat" : 51.96236820,
"lng" : 7.595598700000001
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 51.9846220,
"lng" : 7.6245910
},
"southwest" : {
"lat" : 51.9381030,
"lng" : 7.57505310
}
}
},
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "Münster",
"short_name" : "Münster",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Münster",
"short_name" : "Münster",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "North Rhine-Westphalia",
"short_name" : "NRW",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Germany",
"short_name" : "DE",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Münster, Germany",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 52.06001970,
"lng" : 7.774361699999999
},
"southwest" : {
"lat" : 51.84015110000001,
"lng" : 7.473832599999999
}
},
"location" : {
"lat" : 51.96066490,
"lng" : 7.62613470
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 52.06001970,
"lng" : 7.774361699999999
},
"southwest" : {
"lat" : 51.84015110000001,
"lng" : 7.473832599999999
}
}
},
"types" : [ "locality", "political" ]
},
{
"address_components" : [
{
"long_name" : "Münster",
"short_name" : "Münster",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "North Rhine-Westphalia",
"short_name" : "NRW",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Germany",
"short_name" : "DE",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Münster, Germany",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 52.47498539999999,
"lng" : 8.320101899999999
},
"southwest" : {
"lat" : 51.48078280,
"lng" : 6.386867199999999
}
},
"location" : {
"lat" : 51.94711969999999,
"lng" : 7.584531999999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 52.47498539999999,
"lng" : 8.320101899999999
},
"southwest" : {
"lat" : 51.48078280,
"lng" : 6.386867199999999
}
}
},
"types" : [ "administrative_area_level_2", "political" ]
},
{
"address_components" : [
{
"long_name" : "North Rhine-Westphalia",
"short_name" : "NRW",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Germany",
"short_name" : "DE",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "North Rhine-Westphalia, Germany",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 52.53146959999999,
"lng" : 9.461634900000002
},
"southwest" : {
"lat" : 50.3227010,
"lng" : 5.86634250
}
},
"location" : {
"lat" : 51.43323669999999,
"lng" : 7.661593799999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 52.53146959999999,
"lng" : 9.461634900000002
},
"southwest" : {
"lat" : 50.3227010,
"lng" : 5.86634250
}
}
},
"types" : [ "administrative_area_level_1", "political" ]
},
{
"address_components" : [
{
"long_name" : "Germany",
"short_name" : "DE",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Germany",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 55.0583470,
"lng" : 15.04189620
},
"southwest" : {
"lat" : 47.27011150,
"lng" : 5.86634250
}
},
"location" : {
"lat" : 51.1656910,
"lng" : 10.4515260
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 55.0583470,
"lng" : 15.04189620
},
"southwest" : {
"lat" : 47.27011150,
"lng" : 5.86634250
}
}
},
"types" : [ "country", "political" ]
}
],
"status" : "OK"
}

Related

How do I restrict the Google Maps geocoder?

I've got a web page that allows a user to type a location into an input and find which of my company's physical locations are nearest. It works, mostly. We have LatLngs for all our business locations; we send the user's input to the Google Geocoding API and get a LatLng from there to find the closest.
I'm trying to solve an issue that comes up when a user isn't very specific. All of our locations are in Texas, so if a user enters "paris" into the input, I'd like the Geocoding API to return a result for Paris, TX. Unfortunately, that input only returns a single result, and it's not the one with the cowboy hat on the Eiffel tower.
I've read about viewport biasing and region biasing; they seem like what I need, but they're not working as I expect. Both https://maps.googleapis.com/maps/api/geocode/json?address=paris&key=MY_KEY&region=us and https://maps.googleapis.com/maps/api/geocode/json?address=paris&key=MY_KEY&bounds=25.837377,-106.645646|36.500704,-93.508292 (as well as combining the two parameters) return only Paris, France. Can anyone suggest something?
You can restrict the Geocoder to the United States with &components=country:US
See component filtering in the documentation
https://maps.googleapis.com/maps/api/geocode/json?address=paris&components=country:US&key=MY_KEY
Returns:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Lamar County",
"short_name" : "Lamar County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Texas",
"short_name" : "TX",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Lamar County, TX, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 33.9430568,
"lng" : -95.3080719
},
"southwest" : {
"lat" : 33.3776528,
"lng" : -95.857738
}
},
"location" : {
"lat" : 33.75694,
"lng" : -95.6457951
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 33.9430568,
"lng" : -95.3080719
},
"southwest" : {
"lat" : 33.3776528,
"lng" : -95.857738
}
}
},
"place_id" : "ChIJf6k5FFj_SoYRwuSdUP31HL0",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"address_components" : [
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "United States",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 71.5388001,
"lng" : -66.885417
},
"southwest" : {
"lat" : 18.7763,
"lng" : 170.5957
}
},
"location" : {
"lat" : 37.09024,
"lng" : -95.712891
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 71.5388001,
"lng" : -66.885417
},
"southwest" : {
"lat" : 18.7763,
"lng" : 170.5957
}
}
},
"place_id" : "ChIJCzYy5IS16lQRQrfeQ5K5Oxw",
"types" : [ "country", "political" ]
},
{
"address_components" : [
{
"long_name" : "156",
"short_name" : "156",
"types" : [ "street_number" ]
},
{
"long_name" : "Paris Street",
"short_name" : "Paris St",
"types" : [ "route" ]
},
{
"long_name" : "Kansas City",
"short_name" : "KCMO",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Carroll Township",
"short_name" : "Carroll Township",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Platte County",
"short_name" : "Platte County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Missouri",
"short_name" : "MO",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "64153",
"short_name" : "64153",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "156 Paris St, Kansas City, MO 64153, USA",
"geometry" : {
"location" : {
"lat" : 39.3044129,
"lng" : -94.7207093
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 39.30576188029149,
"lng" : -94.71936031970849
},
"southwest" : {
"lat" : 39.30306391970849,
"lng" : -94.72205828029151
}
}
},
"place_id" : "ChIJg_6e7QZewIcRDuO25dr6ddg",
"plus_code" : {
"compound_code" : "873H+QP Kansas City, MO, USA",
"global_code" : "86F7873H+QP"
},
"types" : [ "establishment", "finance", "point_of_interest", "post_office" ]
},
{
"address_components" : [
{
"long_name" : "Paris",
"short_name" : "Paris",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Lamar County",
"short_name" : "Lamar County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Texas",
"short_name" : "TX",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Paris, TX, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 33.7383781,
"lng" : -95.435455
},
"southwest" : {
"lat" : 33.6118529,
"lng" : -95.62792789999999
}
},
"location" : {
"lat" : 33.6609389,
"lng" : -95.55551299999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 33.7383781,
"lng" : -95.435455
},
"southwest" : {
"lat" : 33.6118529,
"lng" : -95.62792789999999
}
}
},
"place_id" : "ChIJmysnFgZYSoYRSfPTL2YJuck",
"types" : [ "locality", "political" ]
},
{
"address_components" : [
{
"long_name" : "Edgar County",
"short_name" : "Edgar County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Illinois",
"short_name" : "IL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Edgar County, IL, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 39.88299200000001,
"lng" : -87.53164
},
"southwest" : {
"lat" : 39.476646,
"lng" : -87.96880899999999
}
},
"location" : {
"lat" : 39.71312229999999,
"lng" : -87.77633329999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 39.88299200000001,
"lng" : -87.53164
},
"southwest" : {
"lat" : 39.476646,
"lng" : -87.96880899999999
}
}
},
"place_id" : "ChIJkST6Ms69cogRCAPGWoBqOUQ",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"address_components" : [
{
"long_name" : "Paris",
"short_name" : "Paris",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Lane County",
"short_name" : "Lane County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Oregon",
"short_name" : "OR",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "97390",
"short_name" : "97390",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Paris, OR 97390, USA",
"geometry" : {
"location" : {
"lat" : 44.2526208,
"lng" : -123.7706633
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 44.2606124,
"lng" : -123.7546559
},
"southwest" : {
"lat" : 44.2446281,
"lng" : -123.7866707
}
}
},
"place_id" : "ChIJleXtq1KjwVQRLiSkFazeFHU",
"types" : [ "locality", "political" ]
},
{
"address_components" : [
{
"long_name" : "Jordan",
"short_name" : "Jordan",
"types" : [ "colloquial_area", "political" ]
},
{
"long_name" : "Washington Township",
"short_name" : "Washington Township",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Daviess County",
"short_name" : "Daviess County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Indiana",
"short_name" : "IN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "47501",
"short_name" : "47501",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Jordan, Washington Township, IN 47501, USA",
"geometry" : {
"location" : {
"lat" : 38.6886591,
"lng" : -87.206957
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 38.697368,
"lng" : -87.1909496
},
"southwest" : {
"lat" : 38.6799492,
"lng" : -87.2229644
}
}
},
"place_id" : "ChIJ0e364hPebYgRigmh1xFd6TI",
"types" : [ "colloquial_area", "political" ]
},
{
"address_components" : [
{
"long_name" : "Palestine",
"short_name" : "Palestine",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Paris",
"short_name" : "Paris",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Henry County",
"short_name" : "Henry County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Tennessee",
"short_name" : "TN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "38242",
"short_name" : "38242",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Palestine, Paris, TN 38242, USA",
"geometry" : {
"location" : {
"lat" : 36.2589479,
"lng" : -88.40199149999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 36.2679447,
"lng" : -88.3859841
},
"southwest" : {
"lat" : 36.2499501,
"lng" : -88.4179989
}
}
},
"place_id" : "ChIJ4wFtXAe-e4gRs1UnOjUUm1c",
"types" : [ "neighborhood", "political" ]
},
{
"address_components" : [
{
"long_name" : "Texas",
"short_name" : "TX",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Texas, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 36.5007041,
"lng" : -93.5080389
},
"southwest" : {
"lat" : 25.8371638,
"lng" : -106.6456461
}
},
"location" : {
"lat" : 31.9685988,
"lng" : -99.9018131
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 36.5007041,
"lng" : -93.5080389
},
"southwest" : {
"lat" : 25.8371638,
"lng" : -106.6456461
}
}
},
"place_id" : "ChIJSTKCCzZwQIYRPN4IGI8c6xY",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"address_components" : [
{
"long_name" : "Monroe County",
"short_name" : "Monroe County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Missouri",
"short_name" : "MO",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Monroe County, MO, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 39.662932,
"lng" : -91.711934
},
"southwest" : {
"lat" : 39.3373651,
"lng" : -92.31004899999999
}
},
"location" : {
"lat" : 39.5508815,
"lng" : -92.0665197
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 39.662932,
"lng" : -91.711934
},
"southwest" : {
"lat" : 39.3373651,
"lng" : -92.31004899999999
}
}
},
"place_id" : "ChIJOV2qxv0M3YcRAKucv30D33c",
"types" : [ "administrative_area_level_2", "political" ]
}
],
"status" : "OK"
}

Google Geocode API: 'administrative_area:in|country:US' Not Found

Why does this find Indiana:
https://maps.google.com/maps/api/geocode/json?components=administrative_area:in
But this does not?
https://maps.google.com/maps/api/geocode/json?components=administrative_area:in|country:US
It works fine if you use ind instead of a in.
https://maps.google.com/maps/api/geocode/json?components=country:US|administrative_area:ind&key=
{
"results" : [
{
"address_components" : [
{
"long_name" : "Indiana",
"short_name" : "IN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Indiana, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 41.761368,
"lng" : -84.784662
},
"southwest" : {
"lat" : 37.7717419,
"lng" : -88.097892
}
},
"location" : {
"lat" : 40.2671941,
"lng" : -86.1349019
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 41.761368,
"lng" : -84.784662
},
"southwest" : {
"lat" : 37.7717419,
"lng" : -88.097892
}
}
},
"place_id" : "ChIJHRv42bxQa4gRcuwyy84vEH4",
"types" : [ "administrative_area_level_1", "political" ]
}
],
"status" : "OK"

google maps geocoder not returning locality

My geocoder used to work fine, but now it only returns the county, state and country. According to the docs (https://developers.google.com/maps/documentation/geocoding/intro), the geocoder should return locality (city).
SEARCHING "Winnetka"...
EXPECTED RESULTS:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Winnetka",
"short_name" : "Winnetka",
"types" : [ "locality", "political" ]
},
{
"long_name" : "New Trier",
"short_name" : "New Trier",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Cook County",
"short_name" : "Cook County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Illinois",
"short_name" : "IL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Winnetka, IL, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 42.1282269,
"lng" : -87.7108162
},
"southwest" : {
"lat" : 42.0886089,
"lng" : -87.7708629
}
},
"location" : {
"lat" : 42.10808340000001,
"lng" : -87.735895
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 42.1282269,
"lng" : -87.7108162
},
"southwest" : {
"lat" : 42.0886089,
"lng" : -87.7708629
}
}
},
"place_id" : "ChIJW8Va5TnED4gRY91Ng47qy3Q",
"types" : [ "locality", "political" ]
}
],
"status" : "OK"
}
ACTUAL RESULTS:
{
"results" : [
{
"address_components" : [
{
"long_name" : "New Trier Township",
"short_name" : "New Trier Township",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Cook County",
"short_name" : "Cook County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Illinois",
"short_name" : "IL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "New Trier Township, IL, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 42.1282269,
"lng" : -87.71080979999999
},
"southwest" : {
"lat" : 42.0886089,
"lng" : -87.7708629
}
},
"location" : {
"lat" : 42.10808340000001,
"lng" : -87.735895
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 42.1282269,
"lng" : -87.7108162
},
"southwest" : {
"lat" : 42.0886089,
"lng" : -87.7708629
}
}
},
"place_id" : "ChIJW8Va5TnED4gRY91Ng47qy3Q",
"types" : [ "locality", "political" ]
}
],
"status" : "OK"
}
I am in the same boat as you. The level at which you are searching is not being returned. If you search for a locality, it is missing. If you search for administrative_area_level_1, it is missing.
#geocodezip in another question with the same problem thinks it is server specific. This happens sometimes, usually when google is making a change apparently. It is really hurting me right now though so hopefully it gets resolved soon.

Google Maps API region parameter for postcode search

I want to use Google Maps API to get the coordinates of a postcode.
I am using this documentation: https://developers.google.com/maps/documentation/geocoding/intro?csw=1
When I now want to search for the postcode 1200 (Genève in Switzerland) I use this URL:
https://maps.google.com/maps/api/geocode/json?region=ch&components=postal_code:1200
I get alot of different results, but none in Switzerland (Results of this are at the end of the question). It looks like the region parameter does not work at all because I get results in other counrtys.
When I search for 1201 (also Genève) it works.
Any idea why? I would rather get not any result then wrong results (results in other countries)
{
"results" : [
{
"address_components" : [
{
"long_name" : "1200",
"short_name" : "1200",
"types" : [ "postal_code" ]
},
{
"long_name" : "Region Brüssel-Hauptstadt",
"short_name" : "Region Brüssel-Hauptstadt",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Belgien",
"short_name" : "BE",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "1200, Belgien",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 50.86307189999999,
"lng" : 4.4629024
},
"southwest" : {
"lat" : 50.8337598,
"lng" : 4.3999935
}
},
"location" : {
"lat" : 50.850308,
"lng" : 4.4278228
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 50.86307189999999,
"lng" : 4.4629024
},
"southwest" : {
"lat" : 50.8337598,
"lng" : 4.3999935
}
}
},
"place_id" : "ChIJNa8iqqHcw0cRG4NyYbv66KY",
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "1200",
"short_name" : "1200",
"types" : [ "postal_code" ]
},
{
"long_name" : "Wien",
"short_name" : "Wien",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Wien",
"short_name" : "Wien",
"types" : [ "postal_town" ]
},
{
"long_name" : "Wien",
"short_name" : "Wien",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Österreich",
"short_name" : "AT",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "1200 Wien, Österreich",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 48.2646423,
"lng" : 16.4007913
},
"southwest" : {
"lat" : 48.2252299,
"lng" : 16.3618448
}
},
"location" : {
"lat" : 48.235668,
"lng" : 16.373098
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 48.2646423,
"lng" : 16.4007913
},
"southwest" : {
"lat" : 48.2252299,
"lng" : 16.3618448
}
}
},
"place_id" : "ChIJs0PDoUQGbUcRI9VvmpZbVzQ",
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "1200",
"short_name" : "1200",
"types" : [ "postal_code", "postal_code_prefix" ]
},
{
"long_name" : "Lissabon",
"short_name" : "Lissabon",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Lissabon",
"short_name" : "Lissabon",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Portugal",
"short_name" : "PT",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "1200 Lissabon, Portugal",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 38.7177413,
"lng" : -9.1387655
},
"southwest" : {
"lat" : 38.7006072,
"lng" : -9.168078299999999
}
},
"location" : {
"lat" : 38.7096083,
"lng" : -9.1539178
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 38.7177413,
"lng" : -9.1387655
},
"southwest" : {
"lat" : 38.7006072,
"lng" : -9.168078299999999
}
}
},
"place_id" : "ChIJT3JAUYI0GQ0R4Nc7DsHrABw",
"types" : [ "postal_code", "postal_code_prefix" ]
},
{
"address_components" : [
{
"long_name" : "1200",
"short_name" : "1200",
"types" : [ "postal_code" ]
},
{
"long_name" : "Mbombela",
"short_name" : "Mbombela",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Mbombela",
"short_name" : "Mbombela",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Ehlanzeni",
"short_name" : "Ehlanzeni",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Mpumalanga",
"short_name" : "MP",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Südafrika",
"short_name" : "ZA",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Mbombela, 1200, Südafrika",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -25.434559,
"lng" : 31.035606
},
"southwest" : {
"lat" : -25.5273621,
"lng" : 30.9615131
}
},
"location" : {
"lat" : -25.4922163,
"lng" : 31.0048384
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -25.434559,
"lng" : 31.035606
},
"southwest" : {
"lat" : -25.5273621,
"lng" : 30.9615131
}
}
},
"place_id" : "ChIJC-Upoo1J6B4RbhfORqGdY2s",
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "1200",
"short_name" : "1200",
"types" : [ "postal_code" ]
},
{
"long_name" : "København K",
"short_name" : "København K",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "København",
"short_name" : "København",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Dänemark",
"short_name" : "DK",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "1200 København K, Dänemark",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 55.6788537,
"lng" : 12.581048
},
"southwest" : {
"lat" : 55.6774083,
"lng" : 12.5790574
}
},
"location" : {
"lat" : 55.6780957,
"lng" : 12.5799054
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 55.6794799802915,
"lng" : 12.5814016802915
},
"southwest" : {
"lat" : 55.6767820197085,
"lng" : 12.5787037197085
}
}
},
"place_id" : "ChIJuYvG1hZTUkYREL3-tlYomQk",
"types" : [ "postal_code" ]
}
],
"status" : "OK"
}
Like duncan said, the region code will only influence, not fully restrict, results from the geocoder. To know more about it, check the region biasing.
If you want specific results in a country, then use the component=country instead of a region.
I tried to request the postal_code:1200 in the country Switzerland. And I get zero results. So make that the request that you are using is valid.
https://maps.google.com/maps/api/geocode/json?components=postal_code:1200|country:CH
And if I tried the postal_code:1201, I get the specific results that you want.
https://maps.google.com/maps/api/geocode/json?components=postal_code:1201|country:CH
If you are sure that the postal_code:1200 is valid postal code in Switzerland, then maybe that postal_code is not considered the postal code for Geneva, Switzerland by the Google Maps.
Try to also to check this related SO question that I answered.

How to get the address from the json that is returned by googleapi

How can I get the address from the json that google-api returns
Here is my request url, I didn't included the api in the example url i provided
Here is the example url:
https://maps.googleapis.com/maps/api/geocode/json?latlng=55.567,56.786&key=xyz
How can i get the formatted address that is retured by the google json ?
Here is my json
{
"results" : [
{
"address_components" : [
{
"long_name" : "452377",
"short_name" : "452377",
"types" : [ "postal_code" ]
},
{
"long_name" : "Republic of Bashkortostan",
"short_name" : "Republic of Bashkortostan",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Russia",
"short_name" : "RU",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Republic of Bashkortostan, Russia, 452377",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 55.655173,
"lng" : 57.0644709
},
"southwest" : {
"lat" : 55.36128,
"lng" : 56.6011809
}
},
"location" : {
"lat" : 55.50385139999999,
"lng" : 56.900913
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 55.655173,
"lng" : 57.0644709
},
"southwest" : {
"lat" : 55.36128,
"lng" : 56.6011809
}
}
},
"place_id" : "ChIJ904w9b1u3EMRc1XU4GlYSGs",
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "Karaidelsky District",
"short_name" : "Karaidelsky District",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Republic of Bashkortostan",
"short_name" : "Republic of Bashkortostan",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Russia",
"short_name" : "RU",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Karaidelsky District, Republic of Bashkortostan, Russia",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 56.076375,
"lng" : 57.7045048
},
"southwest" : {
"lat" : 55.463071,
"lng" : 56.230281
}
},
"location" : {
"lat" : 55.73996589999999,
"lng" : 56.8548154
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 56.076375,
"lng" : 57.7045048
},
"southwest" : {
"lat" : 55.463071,
"lng" : 56.230281
}
}
},
"place_id" : "ChIJCQ7oNrlx3EMRbyb2O6_k5OY",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"address_components" : [
{
"long_name" : "Republic of Bashkortostan",
"short_name" : "Republic of Bashkortostan",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Russia",
"short_name" : "RU",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Republic of Bashkortostan, Russia",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 56.53352,
"lng" : 60.00295010000001
},
"southwest" : {
"lat" : 51.57122589999999,
"lng" : 53.1579969
}
},
"location" : {
"lat" : 54.2312172,
"lng" : 56.1645257
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 56.53352,
"lng" : 60.00295010000001
},
"southwest" : {
"lat" : 51.57122589999999,
"lng" : 53.1579969
}
}
},
"place_id" : "ChIJ_UeUVQW02UMRNFQ0VFqKPHA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"address_components" : [
{
"long_name" : "Russia",
"short_name" : "RU",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Russia",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 81.8581221,
"lng" : -169.045286
},
"southwest" : {
"lat" : 41.185353,
"lng" : 19.6403534
}
},
"location" : {
"lat" : 61.52401,
"lng" : 105.318756
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 70,
"lng" : 179
},
"southwest" : {
"lat" : 40,
"lng" : 27
}
}
},
"place_id" : "ChIJ-yRniZpWPEURE_YRZvj9CRQ",
"types" : [ "country", "political" ]
}
],
"status" : "OK"
}
You should use file_get_contents and then json_decode your result and you can get your required answer by results[0]->formatted_address as geocodezip suggests you.
So you should use
<?php
$GoogleApiResult = file_get_contents(https://maps.googleapis.com/maps/api/geocode/json?latlng=55.567,56.786&key=xyz);
$GoogleApiResultDecoded = json_decode($GoogleApiResult);
echo $GoogleApiResultDecoded->results[0]->formatted_address;
?>