Jay A. Little
Jay A. Little

Reputation: 3277

Google Places API with Location Bias returns single distant result

I was using Google Maps API to aid in location searches but unexpectedly get a single distant result for very general searches. So I switched to use Google Places API because of locationbias but now Google Places seems to return only a single location and does not use location bias to narrow the location to the latitude and longitude radius given.

Example:

Text Search = "123 Main St"
Circle Radius = 16000 meters (10 miles)
Lat/Long = 41.761898,-72.674596 (Hartford, Connecticut)

https://maps.googleapis.com/maps/api/place/textsearch/json?inputtype=textquery&key=[KEY]&locationbias=circle:[email protected],-72.674596&query=123+Main+St

Result:

"123 Main St, San Francisco, California"

{
   "html_attributions" : [],
   "results" : [
      {
         "formatted_address" : "123 Main St, San Francisco, CA 94105, USA",
         "geometry" : {
            "location" : {
           "lat" : 37.7917688,
                   "lng" : -122.3944272
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 37.79301167989272,
                  "lng" : -122.3931579701073
               },
               "southwest" : {
                  "lat" : 37.79031202010728,
                  "lng" : -122.3958576298927
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
         "id" : "596b2040c5c04babad99f2c1adcba7e943324bbb",
         "name" : "123 Main St",
         "place_id" : "ChIJZRkIYGSAhYARyXebnnhvMC0",
         "plus_code" : {
            "compound_code" : "QJR4+P6 SoMa, San Francisco, CA, USA",
            "global_code" : "849VQJR4+P6"
         },
         "reference" : "ChIJZRkIYGSAhYARyXebnnhvMC0",
         "types" : [ "street_address" ]
      }
   ],
   "status" : "OK"
}

I would expect it to return either a single result (123 Main St, Hartford Connecticut) respecting the locationbias, or many results, starting with the closest to Hartford, Connecticut.

So how can Google Places API be used with locationbias to return the expected result? Or how can I include some type of location bias to the Google Maps API.

Upvotes: 4

Views: 4855

Answers (1)

Waren
Waren

Reputation: 335

Just to put an answer to this (comment of OP is noted):

textquery accepts location and radius

The following query returns the desired address on the 2nd result :

https://maps.googleapis.com/maps/api/place/textsearch/json?inputtype=textquery&key=API_KEY&location=41.761898,-72.674596&radius=16000&query=123+Main+St

Upvotes: 3

Related Questions