zoukankan      html  css  js  c++  java
  • 使用geo_ip获得当前访问用户所在的城市

    http://ipinfodb.com/

    http://hupengxing.com/blogs/98-%E4%BD%BF%E7%94%A8geo_ip%E8%8E%B7%E5%BE%97%E5%BD%93%E5%89%8D%E8%AE%BF%E9%97%AE%E7%94%A8%E6%88%B7%E6%89%80%E5%9C%A8%E7%9A%84%E5%9F%8E%E5%B8%82

    使用geo_ip获得当前访问用户所在的城市

    2011年08月14日 by xinghu

       今天做东西有个需求,需要显示当前访问用户所在的城市。考虑到要用ip跟城市的对应,找了很多资料,发现有个gem很好地址在 https://github.com/jeroenj/geo_ip

       使用之前需要在http://ipinfodb.com/ 注册一个用户,激活时可以获得自己的key。需要用自己的key来访问该网站的接口。

       示例:

    1
    2
    3
    4
    5
    def self.get_city_by_ip(ip)
        GeoIp.api_key = 'your key'
        ip_info = GeoIp.geolocation(ip)
        ip_info[:city] == "-" ? "beijing" : ip_info[:city].downcase
    end


  • 相关阅读:
    poj 2942 Knights of the Round Table 双连通分量
    zoj 2588 Burning Bridges 桥
    desin pattern
    android
    ubuntu
    centos
    android布局
    gradle
    好站
    tomcat datasource
  • 原文地址:https://www.cnblogs.com/lexus/p/2149197.html
Copyright © 2011-2022 走看看