目录
  • 1、简介
  • 2、引入依赖
  • 3、测试
  • 4、测试结果

1、简介

ip2region,准确率99.9%的离线IP地址定位库,0.0x毫秒级查询,数据库文件大小只有1.5M,提供了java,php,c,python,nodejs,golang,c#等查询绑定和Binary,B树,内存三种查询算法,仓库地址:

https://gitee.com/lionsoul/ip2region

2、引入依赖

<!-- Ip地址获取 -->
<dependency>
    <groupId>net.dreamlu</groupId>
    <artifactId>mica-ip2region</artifactId>
    <version>2.5.4</version>
</dependency>

3、测试

@Autowired
private Ip2regionSearcher ip2regionSearcher;

/**
 * 获取地理位置信息
 *
 * @param ip
 * @return
 */
@GetMapping("test")
public String test(String ip) {
    return ip2regionSearcher.getAddress(ip);
}

访问地址:

http://localhost:8080/common/test?ip=47.107.233.154

4、测试结果

SpringBoot使用ip2region获取地理位置信息的方法

就这么简单,就能根据 IP 获取到了地理位置信息,还支持多种格式的返回信息,具体可查询源码

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。