本文共 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/