user673551
user673551

Reputation: 101

Google Places API Returns a result far away from the search center

Here is a query that I believe should produces hotel with the same name very closed to the reference point.

https://maps.googleapis.com/maps/api/place/textsearch/xml?key=_your_api_key_goes_in_here_&sensor=false&language=en&location=56.1995,-4.746&radius=30000&query=ARROCHAR

As yo can see the location is 56.1995,-4.746. This is a place in UK. The query if for a hotel named Arrochar. The hotel does exist. The result look like this :

{
   "html_attributions" : [],
   "results" : [
      {
         "formatted_address" : "Arrochar, Staten Island, NY, USA",
         "geometry" : {
            "location" : {
               "lat" : 40.59234250,
               "lng" : -74.07407289999999
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 40.60012790,
                  "lng" : -74.05918419999999
               },
               "southwest" : {
                  "lat" : 40.5779020,
                  "lng" : -74.08570610
               }
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
         "id" : "c7d9f74dca8676759bfe7ea168b8547cd6de3c5e",
         "name" : "Arrochar",
         "reference" : "CpQBiAAAAKYklx4_uV5ovlJP-x-fGr2VAqzhUCRQ2icNBXj2b5TkGZMqix3tL4xyTizwa0_UdZ5VDbI3psEagu0tTiFc2N6Awn2OJE4Oc3NXtXyaUlADLhJKwnZSuMFLFv85ia3AKiR9fFVWH96u6lEcC16foKMyFREY_KR6Z97QdShfiJCPYNlYZye49gsdU0UsIx3YbxIQa5LUZiMGZvW8sQHn_Cog-hoUr4bMXlYdo9Xae82ZRL-BEDSKRAw",
         "types" : [ "neighborhood", "political" ]
      }
   ],
   "status" : "OK"
}

As one can see this place is in US and it is more than 5000 km away. Now, if one goes and modifies the query too look like this:

https://maps.googleapis.com/maps/api/place/textsearch/xml?key=_your_api_key_goes_in_here_&sensor=false&language=en&location=56.1995,-4.746&radius=30000&query=hotel+ARROCHAR

Then the correct result appear:

{
   "formatted_address" : "Main Street, Arrochar, United Kingdom",
   "geometry" : {
      "location" : {
         "lat" : 56.199560,
         "lng" : -4.7459760
      }
   },
   "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/lodging-71.png",
   "id" : "78d53766dfb2c3bb6008301b079423fffb78b801",
   "name" : "Arrochar Hotel",
   "reference" : "CnRtAAAAJPg2ABkegIT9Q12hABjfGezwGgHCc3ur1W761rhtkQq0n6Id-cgaLREU-g8Uo5Bnw4ovaAnqCrYm_fHEKjBHOrHK5dvcGpAndQVsl-zi_qZSZR6Sa5HvYZI4pA3ne3rNTl0m4TwuwmMM0nx2gSkxEBIQFqgW85GrUZI8SQFvohgMiBoU51C716M4m-ySUVECgT4BFZUYB50",
   "types" : [ "lodging", "establishment" ]
}

So why is Places API text search acting like that? Note, the location parameter point to the exact place where the hotel is. Yet, I get something that is 5000 km away, unless I add the word 'hotel'.

Thanks

Upvotes: 2

Views: 1301

Answers (1)

Armando
Armando

Reputation: 485

This is pretty old but just in case, I believe you should use nearbysearch instead of textsearch. (In your url)

Based on Google Places API documentation, your search has nothing to do with an specific location/distance.

Take into account that by using 'nearby search,' location and radius are required parameters. 'textsearch' just requires query and key.

Note: Radius might be required not to be included if using rankby=distance. Check the documentation for more details.

Good luck.

Upvotes: 1

Related Questions