How do I restrict the Google Maps geocoder? - google-maps

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"
}

Related

Google Geocoding API Not Returning adminstrative area level 2

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!

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 not taking street

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

JSON status code 610

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"
}

Why bounding doesn't work in this Google MAP API?

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.