开发者

Smart ways to determine if a search request is an address or a business for use in Google APIS?

开发者 https://www.devze.com 2022-12-15 08:16 出处:网络
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 resu

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 c开发者_开发知识库ould try and handroll something, but I'm wondering if someone has already done this or Google provides such functionality themselves.

Cheers.


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消