1. GPS坐标(经纬度)转化为地理位置(省市区)
  2. 两个位置(经纬度)之间的距离,精确到米
  3. 需要导入GsonJsonParser相关的jar包或者maven依赖
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;import java.util.Map;import static java.lang.Math.*;
import static java.lang.Math.PI;//经纬度转化为省市区
@Component
public class LocationUtil {private static Logger logger = LoggerFactory.getLogger(LocationUtil.class);@Autowiredprivate RestTemplate restTemplate;@Value("${com.address.analyze.urlString}")private String urlString;@Value("${com.address.analyze.user}")private String urlUser;/*** 通过经纬度信息得到地理位置信息*/public String getAddress(String latitude, String longitude) throws RuntimeException{//latitude  纬度 //longitude  经度 //http://116.196.105.215:1234/gis?auth_user=freevip&latitude=39.880655&longitude=116.354386if (StringUtils.isBlank(longitude) || StringUtils.isBlank(latitude)) {logger.debug("longitude or longitude is blank... longitude : {} , longitude : {}.", longitude, latitude);throw new RuntimeException("fail.logOrLat.blank");}String url = urlString.replace("{auth_user}", urlUser).replace("{longitude}", longitude).replace("{latitude}", latitude);String addressInfoString = restTemplate.getForObject(url, String.class);Map<String, Object> addressInfo = new GsonJsonParser().parseMap(addressInfoString);return analyzeAddressInfo(addressInfo);}/*** 解析结果,得到省市区*/private String analyzeAddressInfo(Map<String, Object> addressInfo) {Map<String, Object> locationMap = (Map<String, Object>) addressInfo.get("data");if (locationMap == null || locationMap.isEmpty()) {return "";}StringBuffer result = new StringBuffer();for (Map.Entry<String, Object> entry : locationMap.entrySet()) {if (entry.getKey().contains("zh")) {result.append(entry.getValue());}}return result.toString();}//高德地图可以做验证//https://lbs.amap.com/api/javascript-api/example/calcutation/calculate-distance-between-two-markers//https://lbs.amap.com/console/show/picker/*** 地球半径*/private static double EARTH_RADIUS = 6378137;/*** 两个经纬度之间的直线距离,精确到米*/public double getDistance(double lat1, double lng1, double lat2, double lng2) {double radLat1 = Rad(lat1);double radLng1 = Rad(lng1);double radLat2 = Rad(lat2);double radLng2 = Rad(lng2);double a = radLat1 - radLat2;double b = radLng1 - radLng2;double result = 2 * asin(sqrt(pow(sin(a / 2), 2) + cos(radLat1) * cos(radLat2) * pow(sin(b / 2), 2))) * EARTH_RADIUS;return result;}/*** 经纬度转化成弧度*/private double Rad(double d) {return d * PI / 180d;}
}

配置

#经纬度转化为省市区
com.address.analyze.urlString=http://116.196.105.215:1234/gis?auth_user={auth_user}&latitude={latitude}&longitude={longitude}
com.address.analyze.user=freevip

Java GPS 经纬度 相关操作相关推荐

  1. java ip地址相关操作

    java ip地址相关操作 @(JAVA)[scala] 参考CORE JAVA. 在JAVA中,InetAddress类用于操作与IP地址相关的内容,常用方法如下: java.net.InetAdd ...

  2. java 发送邮件 email相关操作代码测试,生成复杂格式邮件,发送邮件相关操作

    项目源码下载:http://download.csdn.net/detail/liangrui1988/6720047 效果图: 相关代码: test1 package com.mail;import ...

  3. java gps经纬度坐标转高德坐标_RN中Geolocation的经纬度坐标转换为高德地图坐标

    Geolocation经纬度转换为高德地图经纬度方法 直接调用如下GPS. gcj_encrypt(lat, lon)就行了 var GPS = { PI : 3.14159265358979324, ...

  4. java gps经纬度坐标转高德坐标_高德经纬度转普通GPS经纬度

    # 官方API: http://lbs.amap.com/api/webservice/guide/api/convert # 坐标体系说明:http://lbs.amap.com/faq/top/c ...

  5. 正则表达式及其在Java和Python中的相关操作

    1.PCRE表达式全集1 字符 描述 \ 将下一个字符标记为一个特殊字符.或一个原义字符(有^$()*+?.[\{|共计12个)或一个向后引用或一个八进制转义符 ^ 匹配输入字符串的开始位置 $ 匹配 ...

  6. java导入包大全_eclipse快速导入jar包的相关操作步骤

    eclipse怎样快速导入jar包呢?熟悉这款软件是非常简单的,今天小编就分享了关于eclipse快速导入jar包,有需要的朋友一起来看看吧! eclipse快速导入jar包的相关操作步骤 方法1·最 ...

  7. java communiframe_[Java教程]javascript iframe相关操作

    [Java教程]javascript iframe相关操作 0 2014-08-21 21:02:45 1. 获得iframe的window对象 iframeElement.contentWindow ...

  8. Java String类的相关操作

    Java String类的相关操作 一.如何遍历字符串 //法一 String str="hello world"; for(int i=0;i<str.length();i ...

  9. Java时间日期类处理(LocalDateTime、LocalDate相关操作、获取周几、工作日休息日节假日判定)

    1.LocalDateTime相关操作:(时间推移.计算两个LocalDateTime之间的时间间隔.转LocalDate),代码如下: // 获取LocalDateTime对象String date ...

最新文章

  1. Error creating bean with name ‘multipartResolver‘: Lookup method resolution failed; 上传文件异常
  2. ApartmentState.STA
  3. XP系统下建立WIFI热点让手机、电脑能上网
  4. 将AspectJ与NetBeans平台开发集成
  5. 解决Ubuntu下切换到root用户后没有声音问题
  6. Enterprise Continuous Integration with Binary Dependencies example
  7. 王道计算机考研课件,王道考研计算机组成原理课件ppt
  8. 【全网最全面C语言教程】C语言从入门到精通
  9. 达人评测 i510400f和i511400f区别 i5 11400f和i5 10400f对比
  10. qq2018旧版本7.3.1下载_qq下载2020最新版下载安装-qq2020最新版下载V8.4.8-西西软件下载...
  11. 津津乐道播客网络 实习生/志愿者 招募
  12. 网页做服务器的监控界面,服务器监控页面
  13. Python图像处理笔记——形态学处理(skimage.morphology)
  14. TS学习(九) :TS中的泛型
  15. ros中设置Global Options,以及rqt_tf_tree树讲解,TF树的理解,使用GUI插件,用于可视化ROS-TF的框架树
  16. War3快捷键大全—常用的键
  17. RISC-V扩展指令示例
  18. 转载自网易学院 PS打造超级梦幻照片效果
  19. 苹果 谷歌 微软 三国混战 附地图详解
  20. 移动安全--44--MobSF-v3.0框架安装与开发环境搭建

热门文章

  1. linux环境下抓包
  2. 计算机图形学GAMES101(十四)光线追踪(辐射度量学、渲染方程与全局光照)
  3. PlecsMMA学习1
  4. 应用COMSOL Multiphysics建立裂隙流模型
  5. 苹果nfc功能怎么开启_苹果连夜开放NFC——雷霆NFC免电源智能锁开启千亿市场
  6. php递归函数实用吗,php递归函数怎么用才有效
  7. Docker 安装 Nexus3
  8. 驱动人生,FUCK YOU,有没有底线呀
  9. 混合开发Hybrid App为何成为热门?
  10. Cisco路由器忘记密码