All Projects → hsp8712 → addrparser

hsp8712 / addrparser

Licence: Apache-2.0 license
Tool for parsing longitude/latitude to region info in china 根据经纬度解析省市区信息工具包

Programming Languages

java
68154 projects - #9 most used programming language

Labels

Build Status Maven Central GitHub release License

addrparser

离线高效的解析中国范围内的经纬度为省市区信息,省市区信息包括: 行政区划编码、行政区划中文名称、行政区域的中心点经纬度,行政区域的边界点经纬度集合。

依赖安装

依赖 jdk1.8

Maven

<dependency>
    <groupId>tech.spiro</groupId>
    <artifactId>addrparser</artifactId>
    <version>1.1</version>
</dependency>

Jar文件

addrparser-1.1

使用说明-解析地址

下载数据文件

china-region-20190902.zip 解压后得到文件:china-region.json,文件中包括了所有的省市区行政区域信息,包括编码、名称、中心点、边界点集合。

经纬度数据基于GCJ-02坐标系

方式一 (文件)

直接使用china-region.json文件作为基础数据。

示例代码:

// china-region.json文件作为基础数据
RegionDataInput regionDataInput = new JSONFileRegionDataInput("path/china-region.json");

// 创建并初始化位置解析引擎,一般配置为全局单例
LocationParserEngine engine = new LocationParserEngine(regionDataInput);
// 初始化,加载数据,比较耗时
engine.init();

// 执行解析操作
Location location = engine.parse(118.750934,32.038634);

// 获取省市区信息
RegionInfo provInfo = location.getProv();
RegionInfo cityInfo = location.getCity();
RegionInfo districtInfo = location.getDistrict();

方式二 (MySQL)

将数据导入mysql数据库,使用mysql中数据作为基础数据。

下载数据导入工具: addrparser-1.1.tar.gz

或通过源码编译工具: mvn clean package -P tool

解压后,进入addrparser/bin目录,执行jsonfile2mysql.sh (Linux) 或 jsonfile2mysql.bat (Windows)

usage: JSONFile2MySQL
 -a,--password <arg>     MySQL password
 -d,--db <arg>           MySQL database
 -f,--file <arg>         Json region data file path  上述china-region.json文件的路径
 -h,--host <arg>         MySQL host
 -i,--init               Init table schema
 -p,--port <arg>         MySQL port, default 3306
 -t,--table-name <arg>   Default: 'region_data', Region data table name
 -u,--user <arg>         MySQL user

如果不指定-t,使用默认表名region_data

示例代码:

// javax.sql.DataSource 数据源
DataSource ds = ...;

// 关系型数据库区域数据输入
RegionDataInput regionDataInput = new RdbmsRegionDataInput(ds);

// 如果上述命令如果指定了定制的表名,则该处也要指定表名。
// RegionDataInput regionDataInput = new RdbmsRegionDataInput(ds, customTableName);

// 创建并初始化位置解析引擎,一般配置为全局单例
LocationParserEngine engine = new LocationParserEngine(regionDataInput);
// 初始化,加载数据,比较耗时
engine.init();

// 执行解析操作
Location location = engine.parse(118.750934,32.038634);

// 获取省市区信息
RegionInfo provInfo = location.getProv();
RegionInfo cityInfo = location.getCity();
RegionInfo districtInfo = location.getDistrict();

使用说明-地图工具

tech.spiro.addrparser.tool.MapTools 类中包含了常用的地图工具方法:

getPoint2PointDistance

获取点到点的距离

getPoint2LineDistance

获取点到直线的距离

inCircleArea

判断点是否在圆形范围内

inRectangleArea

判断点是否在矩形范围内

inPolygonArea

判断点是否在多边形范围内

yawing

判断点是否偏离一个轨迹

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].