查找最近的咖啡馆和特定纬度铁路的机场

时间:2016-04-06 10:36:28

标签: ruby-on-rails google-maps rails-geocoder

我有latitudelongitude的地址,我想搜索所有机场,火车站,巴士站和咖啡馆等热门地点。我在我的应用程序中使用这些宝石:

gem 'geocoder'
gem 'gmaps4rails'
gem 'geokit-rails

现在请建议我如何解决这个问题?

2 个答案:

答案 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}},其中包含有关咖啡馆等地方的相关信息。

请参阅:https://developers.google.com/places/web-service/search

https://developers.google.com/places/supported_types

答案 1 :(得分:0)

我实际上会使用near function of geocoder,假设您使用ActiveRecord。

相关问题