現在正開發的定位模組用到的定位設置是塞格車聖導航設備,發送指令返回的經緯度需要進行轉換,再到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
JAVA代碼
package com.tdt.test;

 

import com.tdt.api.gis.LocationInfo;

 

/**
* <p>Title:座標轉換 </p>
*
* <p>Description:</p>
*
* <p>Copyright: Copyright (c) 2009</p>
*
* <p>Company:</p>
*
* @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() > {
temp = n1 + temp.substring(temp.indexOf("."),;
}
}
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://sunnylocus.iteye.com/blog/354330
arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()