基于阿里地图围栏数据,Java离线经纬度逆地址解析省份城市

由于项目需要离线本地化,通过离线经纬度解析出省份城市信息

一通查询资料,有非JAVA的,有功能过多过于笨重的,有资源需要收费的

emmm 干脆还是自己动手丰衣足食

技术点:JAVA java.awt.Polygon.contains方法 查询坐标是否包含再多边形中

资源:https://datav.aliyun.com/tools/atlas/index.html 下载所需要的省份城市信息,下载中国城市级别可以参考下面文末下载地图命令 也整理一份到资料中;特别说明,如果解析城市北京上海重庆天津澳门香港位城市级别需要使用中国100000_full.json中数据作为城市级别,否则会解析为区级别 比如朝阳区。

思路:

根据阿里云给出的地图围栏信息生成省份城市的地图多边形围栏,查询判断经纬度是否再多边形范围内,即可查询到经纬度属于哪个城市

注意:

1.省份可能存在多个多边形围栏,多个多边形围栏对应相同省份城市

2.直辖市港澳需要特殊处理 处理方式见代码map中直辖市港澳台.json

测试初步代码+地图数据见附件

代码可能存在一些问题,仅作为思路验证,运行效率笔记本 4W随机经纬度/秒

代码数据资源地址:https://download.csdn.net/download/u014080107/21740668

中国地图下载命令-计算省份使用

wget https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json;

中国城市地图下载命令-计算城市使用

wget https://geo.datav.aliyun.com/areas_v3/bound/110000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/120000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/130000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/140000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/150000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/210000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/220000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/230000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/310000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/320000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/330000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/340000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/350000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/360000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/370000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/410000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/420000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/430000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/440000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/450000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/460000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/500000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/510000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/520000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/530000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/540000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/610000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/620000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/630000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/640000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/650000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/710000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/810000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/820000_full.json;
wget https://geo.datav.aliyun.com/areas_v3/bound/100000_JD_full.json;

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
好的,我了解了您的问题。实现高德地图地理围栏设置功能需要使用高德地图的API和Java编程语言。下面是一个简单的Java工具类,可以帮助您实现电子围栏的设置: ```java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; public class GeoFenceTool { private static final String KEY = "您的高德地图API密钥"; // 高德地图API密钥 /** * 创建电子围栏 * * @param name 电子围栏名称 * @param points 电子围栏坐标点(多边形) * @return 返回电子围栏ID */ public static String createGeoFence(String name, String points) { String url = "https://restapi.amap.com/v4/geofence/meta?key=" + KEY; String param = "{\"name\":\"" + name + "\",\"points\":\"" + points + "\"}"; String result = sendPost(url, param); String geofenceId = result.substring(result.indexOf("gid\":\"") + 6, result.indexOf("\",\"name\"")); return geofenceId; } /** * 删除电子围栏 * * @param geofenceId 电子围栏ID * @return 返回删除结果 */ public static String deleteGeoFence(String geofenceId) { String url = "https://restapi.amap.com/v4/geofence/meta/" + geofenceId + "?key=" + KEY; String result = sendDelete(url); return result; } /** * 发送POST请求 * * @param url 请求地址 * @param param 请求参数 * @return 返回请求结果 */ private static String sendPost(String url, String param) { StringBuilder result = new StringBuilder(); BufferedReader in = null; HttpURLConnection conn = null; try { URL realUrl = new URL(url); conn = (HttpURLConnection) realUrl.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setDoOutput(true); conn.getOutputStream().write(param.getBytes()); in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = in.readLine()) != null) { result.append(line); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (in != null) { in.close(); } } catch (IOException e) { e.printStackTrace(); } if (conn != null) { conn.disconnect(); } } return result.toString(); } /** * 发送DELETE请求 * * @param url 请求地址 * @return 返回请求结果 */ private static String sendDelete(String url) { StringBuilder result = new StringBuilder(); BufferedReader in = null; HttpURLConnection conn = null; try { URL realUrl = new URL(url); conn = (HttpURLConnection) realUrl.openConnection(); conn.setRequestMethod("DELETE"); in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = in.readLine()) != null) { result.append(line); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (in != null) { in.close(); } } catch (IOException e) { e.printStackTrace(); } if (conn != null) { conn.disconnect(); } } return result.toString(); } } ``` 使用方法: 1. 在高德地图开放平台上申请API密钥,并将其替换到KEY变量中。 2. 调用createGeoFence方法创建电子围栏,传入电子围栏名称和坐标点参数。坐标点格式为:经度,纬度;经度,纬度;经度,纬度...(多边形)。 3. 如果需要删除电子围栏,调用deleteGeoFence方法并传入电子围栏ID参数。 注意:本工具类仅供参考,具体实现需要根据项目需求进行调整。同时,使用高德地图API时请遵守《高德地图开放平台服务协议》等相关法律法规。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值