Related
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®ion=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"
}
We're using the Google Geocoding API to populate the County field in a database of store locations. The API returns a location's County in the "administrative_area_level_3" node of the result set.
An example of the result set we'd expect is:
"results" : [
{
"address_components" : [
{
"long_name" : "1100",
"short_name" : "1100",
"types" : [ "street_number" ]
},
{
"long_name" : "Front Street",
"short_name" : "Front St",
"types" : [ "route" ]
},
{
"long_name" : "Morgan City",
"short_name" : "Morgan City",
"types" : [ "locality", "political" ]
},
{
"long_name" : "6",
"short_name" : "6",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "St. Mary County",
"short_name" : "St Mary County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Louisiana",
"short_name" : "LA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "70380",
"short_name" : "70380",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "1100 Front St, Morgan City, LA 70380, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 29.7015251,
"lng" : -91.21346009999999
},
"southwest" : {
"lat" : 29.701518,
"lng" : -91.213477
}
},
"location" : {
"lat" : 29.701518,
"lng" : -91.213477
},
"location_type" : "RANGE_INTERPOLATED",
"viewport" : {
"northeast" : {
"lat" : 29.7028705302915,
"lng" : -91.21211956970848
},
"southwest" : {
"lat" : 29.7001725697085,
"lng" : -91.2148175302915
}
}
},
"place_id" : "EikxMTAwIEZyb250IFN0LCBNb3JnYW4gQ2l0eSwgTEEgNzAzODAsIFVTQQ",
"types" : [ "street_address" ]
}
],
"status" : "OK"
Ocassionally, the API returns a result set that does not contain the administrative_area_level_3 node. For example:
"results" : [
{
"address_components" : [
{
"long_name" : "48th Street",
"short_name" : "48th St",
"types" : [ "route" ]
},
{
"long_name" : "Newport News",
"short_name" : "Newport News",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Virginia",
"short_name" : "VA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "48th St, Newport News, VA, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 37.004314,
"lng" : -76.40833950000001
},
"southwest" : {
"lat" : 36.992475,
"lng" : -76.439454
}
},
"location" : {
"lat" : 36.9986291,
"lng" : -76.4239863
},
"location_type" : "GEOMETRIC_CENTER",
"viewport" : {
"northeast" : {
"lat" : 37.004314,
"lng" : -76.40833950000001
},
"southwest" : {
"lat" : 36.992475,
"lng" : -76.439454
}
}
},
"partial_match" : true,
"place_id" : "ChIJf4pmrRCduokR6tpCG9H5Wbg",
"types" : [ "route" ]
},
{
"address_components" : [
{
"long_name" : "2306",
"short_name" : "2306",
"types" : [ "street_number" ]
},
{
"long_name" : "48th Street",
"short_name" : "48th St",
"types" : [ "route" ]
},
{
"long_name" : "Briarfield",
"short_name" : "Briarfield",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Hampton",
"short_name" : "Hampton",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Virginia",
"short_name" : "VA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "23661",
"short_name" : "23661",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "2306 48th St, Hampton, VA 23661, USA",
"geometry" : {
"location" : {
"lat" : 37.004314,
"lng" : -76.40833950000001
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 37.0056629802915,
"lng" : -76.40699051970851
},
"southwest" : {
"lat" : 37.0029650197085,
"lng" : -76.40968848029152
}
}
},
"partial_match" : true,
"place_id" : "ChIJGTG5l9-cuokRmnDAATl0HQI",
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
We did some research on these addresses, and found that the addresses are correct (no typos). So we're not sure why the API isn't returning the administrative area level 3 value.
Does anyone know why the API doesn't return this node for some of the locations?
Thank you!
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
If I do:
http://maps.googleapis.com/maps/api/geocode/json?address=kemayoran&sensor=false This is the result I want if not for the fact I want this to work when visitors type kem instead of kemayoran.
{
"results" : [
{
"address_components" : [
{
"long_name" : "Kemayoran",
"short_name" : "Kemayoran",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Jakarta Pusat",
"short_name" : "Jakarta Pusat",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Jakarta",
"short_name" : "Jakarta",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Jakarta Capital Region",
"short_name" : "Jakarta Capital Region",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Indonesia",
"short_name" : "ID",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Kemayoran, Jakarta, Indonesia",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -6.14935190,
"lng" : 106.8857620
},
"southwest" : {
"lat" : -6.171493900000001,
"lng" : 106.84546290
}
},
"location" : {
"lat" : -6.16165420,
"lng" : 106.8550150
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -6.14935190,
"lng" : 106.8857620
},
"southwest" : {
"lat" : -6.171493900000001,
"lng" : 106.84546290
}
}
},
"types" : [ "sublocality", "political" ]
},
{
"address_components" : [
{
"long_name" : "Kemayoran",
"short_name" : "Kemayoran",
"types" : [ "train_station", "transit_station", "establishment" ]
},
{
"long_name" : "Jalan Garuda",
"short_name" : "Jalan Garuda",
"types" : [ "route" ]
},
{
"long_name" : "Pasar Baru",
"short_name" : "Pasar Baru",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Sawah Besar",
"short_name" : "Sawah Besar",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Jakarta Pusat",
"short_name" : "Jakarta Pusat",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Jakarta",
"short_name" : "Jakarta",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Jakarta Capital Region",
"short_name" : "Jakarta Capital Region",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Indonesia",
"short_name" : "ID",
"types" : [ "country", "political" ]
},
{
"long_name" : "10710",
"short_name" : "10710",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Kemayoran, Jalan Garuda, Jakarta 10710, Indonesia",
"geometry" : {
"location" : {
"lat" : -6.16204140,
"lng" : 106.84154990
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -6.160692419708497,
"lng" : 106.8428988802915
},
"southwest" : {
"lat" : -6.163390380291502,
"lng" : 106.8402009197085
}
}
},
"types" : [ "train_station", "transit_station", "establishment" ]
},
{
"address_components" : [
{
"long_name" : "Kemayoran",
"short_name" : "Kemayoran",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Kemayoran",
"short_name" : "Kemayoran",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Jakarta Pusat",
"short_name" : "Jakarta Pusat",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Jakarta",
"short_name" : "Jakarta",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Jakarta Capital Region",
"short_name" : "Jakarta Capital Region",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Indonesia",
"short_name" : "ID",
"types" : [ "country", "political" ]
},
{
"long_name" : "10620",
"short_name" : "10620",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Kemayoran, Jakarta 10620, Indonesia",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -6.1602730,
"lng" : 106.8572680
},
"southwest" : {
"lat" : -6.1664210,
"lng" : 106.851820
}
},
"location" : {
"lat" : -6.16165420,
"lng" : 106.8550150
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -6.1602730,
"lng" : 106.8572680
},
"southwest" : {
"lat" : -6.1664210,
"lng" : 106.851820
}
}
},
"types" : [ "sublocality", "political" ]
},
{
"address_components" : [
{
"long_name" : "Kemayoran",
"short_name" : "Kemayoran",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Krembangan",
"short_name" : "Krembangan",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Surabaya",
"short_name" : "Surabaya",
"types" : [ "locality", "political" ]
},
{
"long_name" : "East Java",
"short_name" : "East Java",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Indonesia",
"short_name" : "ID",
"types" : [ "country", "political" ]
},
{
"long_name" : "60176",
"short_name" : "60176",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Kemayoran, Surabaya 60176, Indonesia",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -7.2369960,
"lng" : 112.7333040
},
"southwest" : {
"lat" : -7.2465120,
"lng" : 112.726760
}
},
"location" : {
"lat" : -7.2417540,
"lng" : 112.7300320
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -7.2369960,
"lng" : 112.7333040
},
"southwest" : {
"lat" : -7.2465120,
"lng" : 112.726760
}
}
},
"types" : [ "sublocality", "political" ]
},
{
"address_components" : [
{
"long_name" : "Kemayoran",
"short_name" : "Kemayoran",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Bangkalan",
"short_name" : "Bangkalan",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Bangkalan Regency",
"short_name" : "Bangkalan Regency",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "East Java",
"short_name" : "East Java",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Indonesia",
"short_name" : "ID",
"types" : [ "country", "political" ]
},
{
"long_name" : "69116",
"short_name" : "69116",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Kemayoran, Bangkalan 69116, Indonesia",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -7.0243290,
"lng" : 112.7483040
},
"southwest" : {
"lat" : -7.039670,
"lng" : 112.7349340
}
},
"location" : {
"lat" : -7.031263999999999,
"lng" : 112.7417250
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -7.0243290,
"lng" : 112.7483040
},
"southwest" : {
"lat" : -7.039670,
"lng" : 112.7349340
}
}
},
"types" : [ "sublocality", "political" ]
}
],
"status" : "OK"
}
I got several kemayoran.
If I do:
http://maps.googleapis.com/maps/api/geocode/json?address=kemayoran&sensor=false&bounds=-6,106|-5,107
I got kemayoran. But only one even though all the other kemayoran is well within the bounds.
I specified the bound correctly on first query because as you can all see, the latitude logitude of kemayoran is well within the bounds -6,106|-5,107
If I do
http://maps.googleapis.com/maps/api/geocode/json?address=kemay&sensor=false&bounds=-6,106|-5,107
I got Kemnay instead of kemayoran.
Compare that with this private API:
http://maps.google.com/maps/suggest?q=kemay&cp=2&hl=en&gl=&v=2&clid=1&json=a&ll=-6.230664,106.55365&spn=1,1&src=1&num=20&numps=0
The result is precisely what I want except that it doesn't give latitude and longitude, not to mention being a private API.
So, what should I do?
The bounds is only a way to bias the search results as explained in Google's documentation of the webservice. Since you specify a search string of "Kemay" it finds the exact match in Scotland. However, as observed when you type in the exact string it finds what you're looking for.
EDIT:
It really sounds like you're looking for a functionality like the places autocomplete feature (either via webservice, or better yet via the javascript library). That one seems to give more accurate results while typing in a partial string.