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. 火狐web开发清楚缓存_如何使用Firefox的Web开发工具
  2. python docx runs_别再问我Python怎么操作Word了!
  3. 磁盘管理之逻辑卷管理(Logical Volume Manager)
  4. onvif规范的实现:server端Discovery实现,通过OnvifTestTool12.06测试
  5. dijkstra+priority_queue+vector
  6. 第三章 比特币的实现机制
  7. edius隐藏快捷键_EDIUS 常用快捷键
  8. mumu模拟器Android版本才6,mumu模拟器老版本
  9. NCBI中Entrez Direct的使用
  10. 多x多y的origin图_素雅、便携、多场景,松下纳诺怡X黑科技除菌净味产品使用简评...
  11. 5不触发系统键盘_防盗报警系统基础知识汇总
  12. CC2652RB1F开发板烧录ZNP的固件
  13. Windows10黑体字体
  14. APPSCAN的使用
  15. 天气变冷了,用Python给爸妈制作一个天气提醒小助手
  16. linux查看用户访问记录,Linux记录登录用户的行为
  17. 太阳能基站光照跟随追光逐日PLC控制系统
  18. IPSec基础-IPSec协议类型
  19. java卸载干净_win10系统java如何卸载_win10怎么把java卸载干净
  20. Unity中的网络编程

热门文章

  1. 卸载Windows服务命令sc delete失效
  2. 要怎么礼貌又得体地拒绝掉收到的offer?
  3. 电力电子系统仿真软件--Psim仿真软件设计
  4. 统计学②——概率分布(几何,二项,泊松,正态分布)
  5. Kettle 实战教程
  6. 【Matlab 小波分析工具箱tftb-0.2安装教程】
  7. moment如何转化成24小时制?
  8. 物联网开发笔记(68)- 使用Micropython开发ESP32开发板之使用官方工具esptool烧录
  9. 线性系统理论 matlab,线性系统理论.pdf
  10. Junit3和Junit4区别