ikcodez
ikcodez

Reputation: 323

Search Google Geocoding API by Neighborhood?

Oftentimes, when users are searching businesses by specific location, they might unknowingly input a neighborhood name into the search box thinking that it's a city, but since legally it's just a neighborhood Google API will map it to the actual city center. The problem is that in large cities the two locations (neighborhood center and city center) can be quite a distance apart. For example, if I search Porter Ranch, CA, Google API returns Los Angeles, CA, but the two locations (based on latitude/longitude calculations) are about 23 miles apart, and clearly not what the user intended to see.

Interestingly enough, Google Maps knows Porter Ranch, and if I search "Porter Ranch" it does zoom in on Porter Ranch. And also, if I search a specific address in Porter Ranch, the result is listed as say 123 Main St, Porter Ranch, CA, not as Los Angeles, CA.

So my question is, is there a way to tell Google API to return latitude/longitude of the neighborhood, such as Porter Ranch, instead of the city? I'm hoping there's a way to do this with the API since it works in Maps.

EDIT:

Java example:

GeoApiContext context = new GeoApiContext().setApiKey("xyz");
results = GeoCodingApi.geocode(context, "Porter Ranch, CA").await;

Upvotes: 1

Views: 2856

Answers (1)

xomena
xomena

Reputation: 32100

When I execute a geocoding request for 'Porter Ranch, CA' I can see that the coordinate from the response (34.2822134,-118.5506158) is well centered on this neighborhood.

https://maps.googleapis.com/maps/api/geocode/json?address=Porter%20Ranch%2C%20CA&key=YOUR_API_KEY

Have a look at my screenshot

enter image description here

or check it yourself in the Geocoder tool:

https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3DPorter%2520Ranch%252C%2520CA

So, I cannot see any issue with position of marker, however, indeed the formatted address doesn't include the name of neighborhood.

The unique workaround I can think of is executing a reverse geocoding with type neighborhood and coordinate from the first request:

https://maps.googleapis.com/maps/api/geocode/json?latlng=34.2822134%2C-118.5506158&result_type=neighborhood&key=YOUR_API_KEY

In this case you will get a name of neighborhood in the formatted address string as shown in the following screenshot:

enter image description here

I hope this helps!

Upvotes: 1

Related Questions