wang123

GPS经纬度可以用来Java解析

现在正开发的定位模块用到的定位设置是塞格车圣导航设备,发送指令返回的经纬度需要转换成十进制,再到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 http://www.bt285.cn

Java代码 复制代码
  1. package com.tdt.test;   
  2.   
  3. import com.tdt.api.gis.LocationInfo;   
  4.   
  5. /**  
  6.  * <p>Title:坐标转换 </p>  
  7.  *   
  8.  * <p>Description:</p>  
  9.  *   
  10.  * <p>Copyright: Copyright (c) 2009</p>  
  11.  *   
  12.  * <p>Company:</p>  
  13.  *   
  14.  * @author sunnylocus  
  15.  * @version 1.0 [2009-03-24]  
  16.  *   
  17.  */  
  18. public class LonlatConversion {   
  19.   
  20.     /**  
  21.      *   
  22.      * @param dms 坐标  
  23.      * @param type 坐标类型  
  24.      * @return String 解析后的经纬度  
  25.      */  
  26.     public static String xypase(String dms, String type) {   
  27.         if (dms == null || dms.equals("")) {   
  28.             return "0.0";   
  29.         }   
  30.         double result = 0.0D;   
  31.         String temp = "";   
  32.            
  33.         if (type.equals("E")) {//经度   
  34.             String e1 = dms.substring(03);//截取3位数字,经度共3位,最多180度   
  35.                                             //经度是一伦敦为点作南北两极的线为0度,所有往西和往东各180度    
  36.             String e2 = dms.substring(3, dms.length());//需要运算的小数   
  37.   
  38.             result = Double.parseDouble(e1);   
  39.             result += (Double.parseDouble(e2) / 60.0D);   
  40.             temp = String.valueOf(result);   
  41.             if (temp.length() > 9) {   
  42.                 temp = e1 + temp.substring(temp.indexOf("."), 9);   
  43.             }   
  44.         } else if (type.equals("N")) {      //纬度,纬度是以赤道为基准,相当于把地球分两半,两个半球面上的点和平面夹角0~90度   
  45.             String n1 = dms.substring(02);//截取2位,纬度共2位,最多90度   
  46.             String n2 = dms.substring(2, dms.length());   
  47.   
  48.             result = Double.parseDouble(n1);   
  49.             result += Double.parseDouble(n2) / 60.0D;   
  50.             temp = String.valueOf(result);   
  51.             if (temp.length() > 8) {   
  52.                 temp = n1 + temp.substring(temp.indexOf("."), 8);   
  53.             }   
  54.         }   
  55.         return temp;   
  56.     }   
  57.     public static void main(String[] args) {   
  58.         String info="(ONE072457A3641.2220N11706.2569E000.000240309C0000400)";           
  59.         info=info.substring(11,info.length()-13);   
  60.         //纬度   
  61.         String N = info.substring(0, info.indexOf("N"));   
  62.         //经度   
  63.         String E = info.substring(info.indexOf("N")+1,info.indexOf("E"));   
  64.         //请求gis,获取地理信息描述   
  65.         double x = Double.parseDouble(CoordConversion.xypase(E,"E"));   
  66.         double y = Double.parseDouble(CoordConversion.xypase(N,"N"));   
  67.         String result =LocationInfo.getLocationInfo("test", x, y); //System.out.println("径度:"+x+","+"纬度:"+y);   
  68.         System.out.println(result);   
  69.     }   
  70. }  

运行结果

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

posted on 2009-03-26 17:08 阅读(2156) 评论(0)  编辑  收藏

<2009年3月>
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

统计

常用链接

留言簿(3)

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜