我有一个地址的latitude
和longitude
,我想搜索所有机场、火车站、公共汽车站和咖啡馆等热门地点。我在我的应用程序中使用这些宝石:
gem 'geocoder'
gem 'gmaps4rails'
gem 'geokit-rails
现在请建议我如何解决这个问题?
我们可以在type
中传递搜索参数(这些搜索字符串是谷歌建议的)
lat="30.987674"
lng="-45.098753"
doc = JSON.parse(open("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=#{lat},#{lng}&radius=50&type=['cafe']&name=cruise&key=xxxxxx").read)
cords=[]
doc['results'].each do |r|
tmp={}
tmp = r['geometry']['location']
tmp["name"] = r['name']
cords<< r['geometry']['location']
end
这里的cords是hashes
的array
,具有关于场所(例如咖啡馆)的相对信息。
请参阅:https://developers.google.com/places/web-service/search
https://developers.google.com/places/supported_types
假设您使用ActiveRecord,我实际上会使用地理编码器的near
函数。