The Google Maps Places API is a feature-rich family of services to provide map-based applications the ability to search and find establishments, geographic locations, or prominent points of interest.
For applications looking to provide the most accurate business address information, there is an undocumented feature in Places API for matching a business place type when only an address is given as the search criteria.
Requesting address information
The Places Text Search API provides a web service for returning information about a set of places based on a string, such as an address (refer to Places Text Search for more details.) The service is especially useful if the text search is not a fully formed address and/or includes just a business name.
For example, if the address or search string is "124 E 4th St, Loveland, CO", the corresponding API call would be:
- https://maps.googleapis.com/maps/api/place/textsearch/json?query=124 E 4th St, Loveland, CO &key=YOUR_API_KEY
Result: note how only one place_id is returned with a type of "premise". This is an address/premise place type and does not include any business information, even if a business is located at that address.
{
"results" :
[
{
"formatted_address" : "124 E 4th St, Loveland, CO 80537, USA",
...
"place_id" : "ChIJkdH2GQlTaYcRyYKnSZ4PDIk",
...
"types" : [ "premise" ]
}
],
}
Requesting detailed business information
The above example returns address/premise place type information but no business information. It isn't entirely clear whether this address belongs to a business or a residence, whether there are nearby businesses, nor how to request this additional information.
Fortunately, there is an undocumented API feature that allows requesting both address/premise AND business place types in the same request! Continue reading for more details...
Undocumented "place at" feature
As seen in the above API call example, a single address with type "premise" is returned and no business place types are returned. To get more detailed business information using the same API call, there is an undocumented feature - add the text "place at" prefix before the address being queried.
For example, using the same search as before and adding "place at" the API call becomes:
- https://maps.googleapis.com/maps/api/place/textsearch/json?query=place at 124 E 4th St, Loveland, CO &key=YOUR_API_KEY
Result: the abbreviated result is presented below (click the above URL to see full results with your YOUR_API_KEY.) There are several interesting things to note about the results:
- Multiple address results are returned and each has several place types that distinguish whether it is an address/premise or a business
- GMP stores business and address/premise place types separately and each has a unique place_id, therefore address/premise and business place types can have the same address (this is illustrated below by the two records for address 201 E 4th St, Loveland, CO 80537)
- The results eliminate ambiguity and can show specific business types at specific addresses
- To search for address/premise and business place types separately and not have the information in one results set, see the next section Additional options
{
"results" :
[
{ "formatted_address" : "124 E 4th St, Loveland, CO 80537, United States",
...
"place_id" : "ChIJCRJZGQlTaYcRJEfD2eWbENw",
"types" : [ "bar", "restaurant", "food", "point_of_interest", "establishment" ], },
{ "formatted_address" : "325 E 5th St, Loveland, CO 80537, United States",
...
"place_id" : "ChIJEbGILg9TaYcRuF3sLjx9Jrk",
"types" : [ "point_of_interest", "establishment" ], },
{ "formatted_address" : "201 E 4th St, Loveland, CO 80537, United States",
...
"place_id" : "ChIJMXTLKAhTaYcR3iqQvh9a2SQ",
"types" : [ "point_of_interest", "establishment" ], },
{ "formatted_address" : "201 E 4th St, Loveland, CO 80537, United States",
...
"place_id" : "ChIJIQE6JwlTaYcRiF6rQ61wDW8",
"types" : [ "real_estate_agency", "point_of_interest", "establishment" ], },
...
]
}
Additional options
The above example showed how to add "place at" to queries, which returns both address/premise and business place information. Instead of "place at", the prefixes “place with address” or “business with address” can be used and work as follows:
- "place with address" only returns address/premise place matches
- "business with address" only returns business place matches
Following are example API calls using "place with address" and "business with address":
- https://maps.googleapis.com/maps/api/place/textsearch/json?query=place with address 124 E 4th St, Loveland, CO &key=YOUR_API_KEY
- https://maps.googleapis.com/maps/api/place/textsearch/json?query=business with address 124 E 4th St, Loveland, CO &key=YOUR_API_KEY
Conclusion
This article demonstrated how the Google Places Text Search API can be used to return both address/premise and business place types in the same call by including the prefix "place at" in the query. The results provide detailed information about the place types - better granularity of place information.
Comments
0 comments
Please sign in to leave a comment.