根据经纬度解析省市区信息工具包 addrparser

码农软件 · 软件分类 · 常用工具包 · 2019-08-12 21:14:44

软件介绍

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

离线数据可基于文件,也可存于MySQL数据库中。

依赖安装

Maven

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

使用说明

下载数据文件

china-region-20180418.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.0.tar.gz

解压后,进入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();

本文地址:https://codercto.com/soft/d/12233.html

Flexible Pattern Matching in Strings

Flexible Pattern Matching in Strings

Gonzalo Navarro、Mathieu Raffinot / Cambridge University Press / 2007-7-30 / USD 64.99

String matching problems range from the relatively simple task of searching a single text for a string of characters to searching a database for approximate occurrences of a complex pattern. Recent ye......一起来看看 《Flexible Pattern Matching in Strings》 这本书的介绍吧!

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具