我有latitude
和longitude
的地址,我想搜索所有机场,火车站,巴士站和咖啡馆等热门地点。我在我的应用程序中使用这些宝石:
gem 'geocoder'
gem 'gmaps4rails'
gem 'geokit-rails
现在请建议我如何解决这个问题?
答案 0 :(得分:1)
我们可以在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
此处的线索是array
的{{1}},其中包含有关咖啡馆等地方的相关信息。
答案 1 :(得分:0)
我实际上会使用near
function of geocoder,假设您使用ActiveRecord。