hrwath
hrwath

Reputation: 125

Is there a way to get LatLng of a street within particular city using Google Geocoder?

I am writing an application which requires to put a marker on a street within one city. I've added an input for searching this particular street (to simplify the process and not have to drag and locate the street manually).

So, entering "[Street name], [City]" works as expected and locates the street perfectly. However enetering only "[Street name]" centers map on the street but in another city.

Is there a way to tell Geocoder to search in a particular city?

In the end I can manually add ", [City]" to the request but I'm wondering if it's possible through the API.

Upvotes: 1

Views: 347

Answers (1)

Andrew Leach
Andrew Leach

Reputation: 12983

You can tell the geocoder to bias towards a particular area: https://developers.google.com/maps/documentation/javascript/geocoding#GeocodingViewports

Note: this is not entirely foolproof: it biases, it doesn't restrict. So if you look for "Downing Street" in a tiny village it may well find Downing Street in London anyway.

The only foolproof way is to force the city into the address.

Upvotes: 2

Related Questions