博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用Java解析GPS经纬度
阅读量:4156 次
发布时间:2019-05-26

本文共 2464 字,大约阅读时间需要 8 分钟。

 

  现在正开发的定位模块用到的定位设置是塞格车圣导航设备,发送指令返回的经纬度需要进行转换,再到GIS系统获取地理信息描述。以后需要要经常用到这方面的知识,随笔写下。

 

将十进制数值转经纬度

 公式:

    Decimal Degrees = Degrees + minutes/60 + seconds/3600
  例:57°55'56.6" =57+55/60+56.6/3600=57.9323888888888
 
如把经纬度  (longitude,latitude) (205.395583333332,57.9323888888888)转换据成坐标(Degrees,minutes,seconds)(205°23'44.1",57°55'56.6")。
步骤如下:

1、 直接读取"度":205

2、(205.395583333332-205)*60=23.734999999920 得到"分":23

3、(23.734999999920-23)*60=44.099999995200 得到"秒":44.1

 

发送定位指令,终端返回的经纬度信息如下:

(ONE072457A3641.2220N11706.2569E000.000240309C0000400)

按照协议解析

 

获得信息体的经纬度是主要,其它不要管,直接用String类的substring()方法截掉,获取的经纬度

3641.2220N11706.2569E

package com.tdt.test;import com.tdt.api.gis.LocationInfo;/** * 

Title:坐标转换

* *

Description:

* *

Copyright: Copyright (c) 2009

* *

Company:

* * @author sunnylocus * @version 1.0 [2009-03-24] * */public class LonlatConversion { /** * * @param dms 坐标 * @param type 坐标类型 * @return String 解析后的经纬度 */ public static String xypase(String dms, String type) { if (dms == null || dms.equals("")) { return "0.0"; } double result = 0.0D; String temp = ""; if (type.equals("E")) {//经度 String e1 = dms.substring(0, 3);//截取3位数字,经度共3位,最多180度 //经度是一伦敦为点作南北两极的线为0度,所有往西和往东各180度 String e2 = dms.substring(3, dms.length());//需要运算的小数 result = Double.parseDouble(e1); result += (Double.parseDouble(e2) / 60.0D); temp = String.valueOf(result); if (temp.length() > 9) { temp = e1 + temp.substring(temp.indexOf("."), 9); } } else if (type.equals("N")) { //纬度,纬度是以赤道为基准,相当于把地球分两半,两个半球面上的点和平面夹角0~90度 String n1 = dms.substring(0, 2);//截取2位,纬度共2位,最多90度 String n2 = dms.substring(2, dms.length()); result = Double.parseDouble(n1); result += Double.parseDouble(n2) / 60.0D; temp = String.valueOf(result); if (temp.length() > 8) { temp = n1 + temp.substring(temp.indexOf("."), 8); } } return temp; } public static void main(String[] args) { String info="(ONE072457A3641.2220N11706.2569E000.000240309C0000400)"; info=info.substring(11,info.length()-13); //纬度 String N = info.substring(0, info.indexOf("N")); //经度 String E = info.substring(info.indexOf("N")+1,info.indexOf("E")); //请求gis,获取地理信息描述 double x = Double.parseDouble(CoordConversion.xypase(E,"E")); double y = Double.parseDouble(CoordConversion.xypase(N,"N")); String result =LocationInfo.getLocationInfo("test", x, y); //System.out.println("径度:"+x+","+"纬度:"+y); System.out.println(result); }}

运行结果

在济南市,位于轻骑路和八涧堡路附近;在环保科技园国际商务中心和济南市区贤文庄附近。

 

转载地址:http://edkxi.baihongyu.com/

你可能感兴趣的文章
S3C2440看门狗定时器
查看>>
LDD3源码分析之llseek分析
查看>>
linux read 用法
查看>>
LDD3源码分析之llseek分析(二)
查看>>
printk及控制台的日志级别
查看>>
Linux驱动加载实例
查看>>
UEFI Boot Flow 系列之 SEC Phase
查看>>
Uevent 上报event事件给上层的详细讲解
查看>>
WM8903 codec driver 的详解
查看>>
Linux 下的notifier chain 机制的注册和触发讲解
查看>>
ALSA中Widget、route、kcontrol 命名规则
查看>>
如何在android 中编译alsa-utils工具
查看>>
repo用法详解
查看>>
GIT 的使用方法详解
查看>>
Android sensor hal 详解
查看>>
LCD 驱动过程详解
查看>>
MTK camera image sensor driver
查看>>
Mtk Ft6306 touch 驱动
查看>>
Mtk 下的图形渲染配置文件egl.cfg
查看>>
ARM Linux 3.x的设备树(Device Tree)
查看>>