【问题标题】:Getting user city with Rails3 + Google Maps使用 Rails3 + Google Maps 获取用户城市
【发布时间】:2011-10-31 03:31:15
【问题描述】:

当人们访问我的网站时,我想获取用户的 IP,然后在谷歌地图上定位城市并显示与访问者城市相关的信息。

什么宝石可以帮助我?或者给我一些建议。谢谢。

【问题讨论】:

    标签: ruby-on-rails-3 google-maps-api-3 google-maps-markers


    【解决方案1】:

    与其获取用户的 IP,尤其是如果您预计大多数用户将是移动/手持用户,您最好使用 JavaScript Geolocation 和 Google Maps Reverse Geocoding。请参阅http://dev.w3.org/geo/api/spec-source.htmlhttp://code.google.com/apis/maps/documentation/javascript/services.html#ReverseGeocoding

    另一方面,如果您确实想使用用户的 IP,请查看Center Google Map Based on geocoded IP

    可能有 Gems 可以为您提供这些服务,但如果没有,它们也相当简单。

    【讨论】:

      【解决方案2】:

      Geocoder gem 将为您提供帮助。 This Railscast 解释了如何使用 Geocoder。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-11-18
        • 1970-01-01
        • 1970-01-01
        • 2014-07-11
        • 2018-07-25
        • 1970-01-01
        • 2010-11-17
        • 2015-03-26
        相关资源
        最近更新 更多