2016-06-08 9 views
-1

Ich habe diese Situation: ich diese Anfrage an Google Places API machen:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=25.0788005,-78.4699268&keyword=Tiki Bikini Hut&rankby=distance&key=MY_GOOGLE_API_KEY und Antwort ist:Google Places API Suche seltsame Verhalten

{ 
     "html_attributions": [], 
     "results": [], 
     "status": "ZERO_RESULTS" 
    } 

Aber wenn ich eine text_search versuchen: https://maps.googleapis.com/maps/api/place/textsearch/json?query=Bernie's &radius=15000&location=25.0788005,-78.4699268&key=MY_GOOGLE_API_KEY API gibt einen einzelnen Ort, an dem ich suche.

Auch wenn ich auf Google "Tiki Bikini Hut Bahamas" suche, kommt Google zurück, das ist ein existierender Google Orte-Punkt, der auf Bahamas so genannt wird.

Kann mir jemand helfen und mir erklären, warum ich, wenn ich in der Nähe suche, ZERO_RESULTS bekomme, aber wenn ich Textsuche versuche, bekomme ich den Ort?

Danke!

+0

Im ersten Aufruf geben Sie keinen Radius an, vielleicht entspricht der Standard nicht Ihren Anforderungen. – meucaa

+0

radius parameter ist nicht erlaubt, wenn rankby den Wert "distance" hat. Danke für die Antwort :) – kitz

Antwort

2

der Tat, wie meucaa darauf hingewiesen, ist radius ein erforderlicher Parameter, nach Google Documentation

Sie könnten die Informationen auch mit einem Radius von 0 erhalten, wie folgt aus:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Tiki%20Bikini&location=25.0788005%2C-78.4699268&radius=0&key=YOUR_api_key 

Aber wenn Sie verwenden die nahegelegene Suche, die eine Regel weiterhin anwendet:

Der maximal zulässige Radius beträgt 50 000 Meter.

also Ihre erste LatLng Position ist zu weit von der Stelle, wie Sie in diesem Bild sehen können: tooFar http://i65.tinypic.com/18k8dd.png

So erreichbar sein nicht durch die nearbySearch. Stattdessen, wenn Sie Ihre Abfrage mit einem Zentrum näher an Nassau machen, dann funktioniert es wie beabsichtigt:

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=25.0788005%2C-77.4699268&radius=50000&keyword=tiki%20bikini%20hut&key=YOUR_API_KEY

So das Ergebnis ist folgende: inScope http://i68.tinypic.com/6ztvk5.jpg und das Ergebnis wird in der Karte angezeigt: resultShown http://i65.tinypic.com/2ushr1s.jpg als Sie können in der JSON-Antwort sehen:

{ 
    "html_attributions":[ 

    ], 
    "results":[ 
    { 
     "address_components":[ 
     { 
      "long_name":"Nassau", 
      "short_name":"Nassau", 
      "types":[ 
      "locality","political" 
      ] 
     }, 
     { 
      "long_name":"New Providence", 
      "short_name":"New Providence", 
      "types":[ 
      "administrative_area_level_1","political" 
      ] 
     }, 
     { 
      "long_name":"Bahamas", 
      "short_name":"BS", 
      "types":[ 
      "country","political" 
      ] 
     } 
     ], 
     "formatted_address":"Nassau, Bahamas", 
     "geometry":{ 
     "location":{ 
      "lat":25.0787957,"lng":-77.3493213 
     } 
     }, 
     "icon":"https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png", 
     "id":"ac8051aa71ba5159ac274abfd18f1ed669de6434", 
     "name":"Tiki Bikini Hut", 
     "photos":[ 
     { 
      "height":3006, 
      "html_attributions":[ 
      "Jude D'Souza" 
      ], 
      "photo_reference":"CoQBdwAAAMaD_AgEkLqigcklSzlAb9xpE2Vq8jBVolqarPSF17Z5KvJap4OrtQzIpuX_XpeZt0XQEF5dfh0kwfX-cn5VxIt7KmK3i5EzA6zhJeDSfP3qYEYSyMgyuzyzlmIoqBILXmlpKKSir43awBnp1AVgu_4jQ9hrVcik5gvy6RUIPrFnEhBEVXjUw02krxJiy0TGC1wnGhQtJuqhGJixxwczGnHkTqrdjTKUkA", 
      "width":5344 
     } 
     ], 
     "place_id":"ChIJPQxV1xt9L4kRIAd9AzuTmjQ", 
     "reference":"CnRiAAAAqZmGFHqUBt3PWM3nouhli_jsPWlPt1SSvIv7Lltl6Hr-HVuMXdM5TI6-ksyHMrsIJgkKImNFojEidF9HGd_q0FA89l0TxmEBYWIW53Km5xhU0KXKXNQk4O7LZnwh5Qvs5QaLftI_AUC90443Lq84kBIQqAgc2yeqTjVFsd2JOkf55RoUNBA65tTK-S7lqWXmYlX5SbPi_Ek", 
     "scope":"GOOGLE", 
     "types":[ 
     "bar","restaurant","food","point_of_interest","establishment" 
     ], 
     "url":"https://maps.google.com/?cid=3790503918056572704", 
     "vicinity":"Nassau" 
    }, 
    { 
     "address_components":[ 
     { 
      "long_name":"Nassau Street", 
      "short_name":"Nassau St", 
      "types":[ 
      "route" 
      ] 
     }, 
     { 
      "long_name":"Nassau", 
      "short_name":"Nassau", 
      "types":[ 
      "locality","political" 
      ] 
     }, 
     { 
      "long_name":"New Providence", 
      "short_name":"New Providence", 
      "types":[ 
      "administrative_area_level_1","political" 
      ] 
     }, 
     { 
      "long_name":"Bahamas", 
      "short_name":"BS", 
      "types":[ 
      "country","political" 
      ] 
     } 
     ], 
     "formatted_address":"Nassau St, Nassau, Bahamas", 
     "formatted_phone_number":"(242) 322-1514", 
     "geometry":{ 
     "location":{ 
      "lat":25.0782201,"lng":-77.3501194 
     } 
     }, 
     "icon":"https://maps.gstatic.com/mapfiles/place_api/icons/lodging-71.png", 
     "id":"a2397730559fc6850c1c3ac273e35847786e3ca6", 
     "international_phone_number":"+1 242-322-1514", 
     "name":"Nassau Junkanoo Beach Resort", 
     "photos":[ 
     { 
      "height":2097, 
      "html_attributions":[ 
      "Kordian Witek" 
      ], 
      "photo_reference":"CoQBcwAAANk0iMSTxkpqkAGf2jTCLLwgRs-XLjxJJCuVFI6PDdjCK_29S7SxHDfGw2w9t0FXJS9RoSv61IqLYZ1uhF-Ei8mTFL2_350LegRreTUrUj5WsDG62__jhfhohO--2FENQfew9x4_Gk94KO_dgF0ootACEPz4ZbSJntUlbLnYfHlQEhBE-ul_zRlsNEndOGjPNueFGhQg6-tPWCDvePiJQXdeQe0DnM22xg", 
      "width":4932 
     } 
     ], 
     "place_id":"ChIJmZDMZhl9L4kR58vJmbsRXnU", 
     "rating":4.5, 
     "reference":"CnRvAAAAZvZhtQWqFBfYvtoVmZ-ANvTtkDK8vwTi9Mijl7TBIE72zXCh1SQA9M1xwicDmJsQhBtVDhkEAQcrQzpbFhMQEXHXajLnchXYW89l3v6_Ky-7PnDqEm7P9W3CWRmUe9ILb4ymzumZsVN3aAz1UyfRYhIQYAdXrIYNTKBX6MGi4MVrNBoUcrr4ojzxv9rktXdcHJ0we4xmw2I", 
     "scope":"GOOGLE", 
     "types":[ 
     "lodging","point_of_interest","establishment" 
     ], 
     "url":"https://maps.google.com/?cid=8457216647685065703", 
     "vicinity":"Nassau Street, Nassau" 
    } 
    ], 
    "status":"OK" 
} 
+0

Ich brauche einen nahe gelegenen_Suchvorgang, nicht automatisch vervollständigen. – kitz

+0

Ich habe vergessen, Ihnen zu sagen, dass ich meine Antwort aktualisiert habe. Ich hoffe, es hilft –