将经纬度转换成十进制
公式:
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代码
packagecom.tdt.test;
importcom.tdt.api.gis.LocationInfo;
/**
*
Title:坐标转换
*
*
Description:
*
*
Copyright: Copyright (c) 2009
*
*
Company:
*
* @author sunnylocus
* @version 1.0 [2009-03-24]
*
*/
publicclassLonlatConversion {
/**
*
* @param dms 坐标
* @param type 坐标类型
* @return String 解析后的经纬度
*/
publicstaticString xypase(String dms, String type) {
if(dms ==null|| dms.equals("")) {
return"0.0";
}
doubleresult =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);
}
}elseif(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);
}
}
returntemp;
}
publicstaticvoidmain(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,获取地理信息描述
doublex = Double.parseDouble(CoordConversion.xypase(E,"E"));
doubley = Double.parseDouble(CoordConversion.xypase(N,"N"));
String result =LocationInfo.getLocationInfo("test", x, y);//System.out.println("径度:"+x+","+"纬度:"+y);
System.out.println(result);
}
}
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 http://www.guihua.org )";
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);
}
}
运行结果
在济南市,位于轻骑路和八涧堡路附近;在环保科技园国际商务中心和济南市区贤文庄附近。
posted on 2009-03-26 17:08 王 阅读(2035) 评论(0) 编辑 收藏