Open drnic opened 4 years ago
Prediction#list_by_input is more flexible (allows any options); and supports distance_meters field if origin parameter provided
https://developers.google.com/places/web-service/autocomplete#place_autocomplete_results
With distance_meters, you can sort the predictions by closeness to the origin:
distance_meters
origin
# pp client.predictions_by_input("wal", origin: "40.730610,-73.935242", location: "40.730610,-73.935242").sort {|p1, p2| p1.distance_meters.to_i <=> p2.distance_meters.to_i}.map {|p| [p.description, p.distance_meters]} [["Wall Street, New York, NY, USA", nil], ["Waldorf Astoria, Park Avenue, New York, NY, USA", 4262], ["Walmart Supercenter, Park Plaza Drive, Secaucus, NJ, USA", 11376], ["Walmart Supercenter, 88th Street, North Bergen, NJ, USA", 11379], ["Wallington, NJ, USA", 20286]]
The .distance_meters.to_i was necessary because the "Wall Street" entry was distance_meters == nil 🤷
.distance_meters.to_i
distance_meters == nil
Prediction#list_by_input is more flexible (allows any options); and supports distance_meters field if origin parameter provided
https://developers.google.com/places/web-service/autocomplete#place_autocomplete_results
With
distance_meters
, you can sort the predictions by closeness to theorigin
:The
.distance_meters.to_i
was necessary because the "Wall Street" entry wasdistance_meters == nil
🤷