views:

57

answers:

2

Here is the problem, I have an app with a search bar, the user can input something like "18th Street" or "Starbucks" and it uses the Google Geocoding and Local Search APIs respectively to get results.

I'm wondering is there a smart way to determine whether or not a given input string is an address that needs to be Geocoded, or a business name that needs to use Local Search.

Obviously I could try and handroll something, but I'm wondering if someone has already done this or Google provides such functionality themselves.

Cheers.

+2  A: 

The first thing that comes to mind would be a regular expression that looks for a street address, but the important question is how your system would qualify an address.

It's reasonable enough to match something that is going to be fairly consistent in format like a fully qualified street address, but when it's something like "18th Street" how do you know they don't actually want a restaurant called "18th Street"? What you might consider is a regular expression that loosely attempts to match a street address and, if it finds one, call the Geocoding. In the event no results are returned by Geocoding, then default to a Local Search.

Nathan Taylor
Thanks a lot for your comment, as it turns out Local Search by default does this and processes Geocodes and business searches. There is some coarseness to it, but I guess that is to be expected.
DevDevDev
+1  A: 

It turns out Local Search by default does this and processes Geocodes and business searches. There is some coarseness to it, but I guess that is to be expected

You can change this behaviour by specifying

mrt? This optional argument specifies which type of listing the user is interested in. Valid values include:

* blended - request KML, Local Business Listings, and Geocode results
* kmlonly - request KML and Geocode results
* localonly - request Local Business Listings and Geocode results
DevDevDev