Related
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"
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.
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.
I have a problem with using Google Maps API. I use a geolocation service for the coordination of streets, but faced with the problem. When I select a street that I need API does not calculate right the coordinates of the street. JSON response shows that the API search only city. This situation only occurs with some streets.
http://maps.googleapis.com/maps/api/geocode/json?address=1+Schorsa+Kyiv&sensor=false
{ "results" : [ { "address_components" : [ { "long_name" : "Kiev", "short_name" : "Kiev", "types" : [ "locality", "political" ] }, { "long_name" : "Kiev city", "short_name" : "Kiev city", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "Kyiv city", "short_name" : "Kyiv city", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "Ukraine", "short_name" : "UA", "types" : [ "country", "political" ] } ], "formatted_address" : "Kiev, Kyiv city, Ukraine", "geometry" : { "bounds" : { "northeast" : { "lat" : 50.590798, "lng" : 30.825941 }, "southwest" : { "lat" : 50.213273, "lng" : 30.2394401 } }, "location" : { "lat" : 50.4501, "lng" : 30.5234 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 50.590798, "lng" : 30.825941 }, "southwest" : { "lat" : 50.213273, "lng" : 30.2394401 } } }, "partial_match" : true, "types" : [ "locality", "political" ] } ], "status" : "OK" }
If you click the link that I send it in a browser
{
"results" : [
{
"address_components" : [
{
"long_name" : "1",
"short_name" : "1",
"types" : [ "street_number" ]
},
{
"long_name" : "улица Щорса",
"short_name" : "улица Щорса",
"types" : [ "route" ]
},
{
"long_name" : "Деснянский район",
"short_name" : "Деснянский район",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Киев",
"short_name" : "Киев",
"types" : [ "locality", "political" ]
},
{
"long_name" : "город Киев",
"short_name" : "город Киев",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "город Киев",
"short_name" : "город Киев",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Украина",
"short_name" : "UA",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "улица Щорса, 1, Киев, город Киев, Украина",
"geometry" : {
"location" : {
"lat" : 50.52287399999999,
"lng" : 30.59185099999999
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 50.5242229802915,
"lng" : 30.59319998029149
},
"southwest" : {
"lat" : 50.5215250197085,
"lng" : 30.5905020197085
}
}
},
Add "Street" to the name of the street
http://maps.googleapis.com/maps/api/geocode/json?address=1+Schorsa+Street+Kyiv&sensor=false
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"
}