Google maps geocode does not give results - google-maps

7-A Artsan Towers Trichy Road,Ramanathapuram, Coimbatore Tamil Nadu
This is what I have typed in google maps, and it gives me 5 results.
But when I give the same address in geocode api, it gives me zero results.
How should I handle this, I would like to have nearest lat long
https://maps.googleapis.com/maps/api/geocode/json?address=7-A%20Artsan%20Towers%20Trichy%20Road,Ramanathapuram,%20Coimbatore%20Tamil%20Nadu&postal_code=641045&key=keyIsHere
Result is
{"results"=>[], "status"=>"ZERO_RESULTS"}

Here you should avoid flat number, floor numbers and business names.
For more info read this
It's worked for me https://maps.googleapis.com/maps/api/geocode/json?address=7A,Artsan%20Towers%20Trich%20Road,Ramanathapuram,Coimbatore%20Tamil%20Nadu&postal_code=641045&key=Your_KEY
Result:
{ "results" : [
{
"address_components" : [
{
"long_name" : "Artsan Towers",
"short_name" : "Artsan Towers",
"types" : [ "premise" ]
},
{
"long_name" : "4",
"short_name" : "4",
"types" : [ "street_number" ]
},
{
"long_name" : "Trichy Road",
"short_name" : "Trichy Rd",
"types" : [ "route" ]
},
{
"long_name" : "Near Ramanathapuram Signal, Behind SS Palamuthir Nilayam",
"short_name" : "Near Ramanathapuram Signal, Behind SS Palamuthir Nilayam",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Ramasamy Nagar",
"short_name" : "Ramasamy Nagar",
"types" : [ "political", "sublocality", "sublocality_level_2" ]
},
{
"long_name" : "Ramanathapuram",
"short_name" : "Ramanathapuram",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "Coimbatore",
"short_name" : "Coimbatore",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Coimbatore",
"short_name" : "Coimbatore",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Tamil Nadu",
"short_name" : "TN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
},
{
"long_name" : "641045",
"short_name" : "641045",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Artsan Towers, 4, Trichy Rd, Near Ramanathapuram Signal, Behind SS Palamuthir Nilayam, Ramasamy Nagar, Ramanathapuram, Coimbatore, Tamil Nadu 641045, India",
"geometry" : {
"location" : {
"lat" : 10.9974156,
"lng" : 76.9949293
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 10.9987645802915,
"lng" : 76.99627828029151
},
"southwest" : {
"lat" : 10.9960666197085,
"lng" : 76.9935803197085
}
}
},
"partial_match" : true,
"place_id" : "ChIJEVWhlsNZqDsR4AxMyrJZQPM",
"types" : [ "street_address" ]
} ], "status" : "OK"}

Related

Google Maps API Doesn't Return LatLng from Extended Zip Code - USA - 9 digit Zip code

The following shows Lat and Long
https://maps.googleapis.com/maps/api/geocode/json?address=90005
But with extended Zip code, it doesn't
https://maps.googleapis.com/maps/api/geocode/json?address=900053200
{
"results" : [],
"status" : "ZERO_RESULTS"
}
Is there a separate service for extended Zip codes?
The format required for zip + 4 is 90005-3200.
Using that format gives me a result (the same result as for zip code 90005).
https://maps.googleapis.com/maps/api/geocode/json?address=90005-3200&key=MY-API-KEY
returns:
{
"results" : [
{
"address_components" : [
{
"long_name" : "90005",
"short_name" : "90005",
"types" : [ "postal_code" ]
},
{
"long_name" : "Central LA",
"short_name" : "Central LA",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Los Angeles",
"short_name" : "Los Angeles",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Los Angeles County",
"short_name" : "Los Angeles County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Los Angeles, CA 90005, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 34.0637149,
"lng" : -118.282294
},
"southwest" : {
"lat" : 34.05513,
"lng" : -118.3393861
}
},
"location" : {
"lat" : 34.0578814,
"lng" : -118.3096648
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 34.0637149,
"lng" : -118.282294
},
"southwest" : {
"lat" : 34.05513,
"lng" : -118.3393861
}
}
},
"partial_match" : true,
"place_id" : "ChIJ0U_geYS4woAR6-RMnUWG2Gc",
"types" : [ "postal_code" ]
}
],
"status" : "OK"
}

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!

Parsing Json Google GeoMaps

I am trying to parse a response from google maps, this is the JSON response.
{ "results" : [ { "address_components" : [ { "long_name" : "11", "short_name" : "11", "types" : [ "street_number" ] }, { "long_name" : "Shottermill", "short_name" : "Shottermill", "types" : [ "route" ] }, { "long_name" : "Horsham", "short_name" : "Horsham", "types" : [ "postal_town" ] }, { "long_name" : "West Sussex", "short_name" : "West Sussex", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "England", "short_name" : "England", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "United Kingdom", "short_name" : "GB", "types" : [ "country", "political" ] }, { "long_name" : "RH12 5HG", "short_name" : "RH12 5HG", "types" : [ "postal_code" ] } ], "formatted_address" : "11 Shottermill, Horsham RH12 5HG, UK", "geometry" : { "location" : { "lat" : 51.084119, "lng" : -0.2948757 }, "location_type" : "ROOFTOP", "viewport" : { "northeast" : { "lat" : 51.0854679802915, "lng" : -0.2935267197084979 }, "southwest" : { "lat" : 51.0827700197085, "lng" : -0.296224680291502 } } }, "place_id" : "ChIJ0ZUiT-_rdUgRadZ4jXXzam4", "types" : [ "street_address" ] } ], "status" : "OK" }
If i want to for example echo out geometry( lat and lng) , how do i do this.
I have tried : ($content contains the above response)
$json = json_decode($content);
echo $json->results->geometry->location->lat;
echo $json->results->geometry->location->lng;
The results is in an array, you should access it using by index
$json->results[0]->geometry->location->lat;
Check the documentation to see if the results array could have a length different to 1. If it is, you will need to iterate through it.

MySQL: filter by value in a JSON string?

I'm trying to implement a query that computes the distance between two pairs of lat/lgn. Assume that my lat/lng values are in a JSON string, would such a query be possible (I'm assuming some string functions might be needed first to extract lat/lng)? And if possible, is it a good idea to do it? Will it scale? Or am I better off having separate columns in the database specifically for lat/lng values?
Example JSON:
{
"results" : [
{
"address_components" : [
{
"long_name" : "1600",
"short_name" : "1600",
"types" : [ "street_number" ]
},
{
"long_name" : "Amphitheatre Parkway",
"short_name" : "Amphitheatre Pkwy",
"types" : [ "route" ]
},
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara County",
"short_name" : "Santa Clara County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "94043",
"short_name" : "94043",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
"geometry" : {
"location" : {
"lat" : 37.4220352,
"lng" : -122.0841244
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 37.42338418029149,
"lng" : -122.0827754197085
},
"southwest" : {
"lat" : 37.4206862197085,
"lng" : -122.0854733802915
}
}
},
"place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
"types" : [ "street_address" ]
}
],
"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.