野火 ATGM332D簡介
高性能、低功耗?GPS、北斗雙模定位模塊
STM32 GPS定位_為了維護世界和平_的博客-CSDN博客
秉火多功能調(diào)試助手上位機開源!共六款軟件,學(xué)到你吐... , - 電腦上位機 - 野火電子論壇 - Powered by Discuz!
https://www.firebbs.cn/forum.php?mod=viewthread&tid=11985&fromuid=64
地圖坐標系之間的轉(zhuǎn)換(百度地圖、GCJ、WGS84)_百度坐標系轉(zhuǎn)wgs84_胖鵝68的博客-CSDN博客
百度地圖API應(yīng)用小實例_百度地圖使用場景100字學(xué)生_海之沐的博客-CSDN博客?根據(jù)百度API處理實際問題
坐標計算距離公式 火星坐標系_地圖坐標轉(zhuǎn)換 -- 火星坐標與GPS坐標_暗夜獵手 Vayne的博客-CSDN博客
國內(nèi)各地圖API坐標系統(tǒng)比較 - Rover.Tang - 博客園
https://www.cnblogs.com/Tangf/archive/2012/03/15/2398397.html
GPS定位及通信協(xié)議解析_gps協(xié)議解析_卷積神經(jīng)網(wǎng)絡(luò)的博客-CSDN博客
4.GPS模塊測試軟件
gps模塊可以使用u-center測試軟件來測試,可以支持串口和網(wǎng)口兩種方式
?
5.相關(guān)軟件下載
數(shù)字地球軟件下載地址:https://download.csdn.net/download/xipengbozai/19774250
GPS測試軟件下載地址:https://download.csdn.net/download/xipengbozai/19774233
GPS數(shù)據(jù)轉(zhuǎn)換工具:https://download.csdn.net/download/xipengbozai/19774213
WGS84地球坐標系,GCJ02火星坐標系,BD09百度坐標系簡介與轉(zhuǎn)換_wgs84坐標系與百度坐標系_ThinkWon的博客-CSDN博客
背景:從GPS和北斗衛(wèi)星定位得到的定位數(shù)據(jù)采用的都是WGS84坐標系,即地球坐標系,但是國內(nèi)不管是高德地圖、百度地圖采用的并不是WGS84坐標系,所以需要經(jīng)過轉(zhuǎn)換后才能使用,前端用百度API提供的方法轉(zhuǎn)換速度較慢。通過網(wǎng)上搜索收集資料,然后自己編寫代碼測試,總結(jié)了一下有關(guān)坐標系簡介與轉(zhuǎn)換的知識,分享給大家!
文章目錄
1.各坐標系簡介
2.各坐標系轉(zhuǎn)換
2.1坐標點實體類
2.2各坐標系轉(zhuǎn)換工具類
3.測試
1.各坐標系簡介
WGS84坐標系
即地球坐標系,國際上通用的坐標系。
設(shè)備一般包含GPS芯片或者北斗芯片獲取的經(jīng)緯度為WGS84地理坐標系。谷歌地圖采用的是WGS84地理坐標系(中國范圍除外,谷歌中國地圖采用的是GCJ02地理坐標系。)
GCJ02坐標系
即火星坐標系,WGS84坐標系經(jīng)加密后的坐標系。
出于國家安全考慮,國內(nèi)所有導(dǎo)航電子地圖必須使用國家測繪局制定的加密坐標系統(tǒng),即將一個真實的經(jīng)緯度坐標加密成一個不正確的經(jīng)緯度坐標。
BD09坐標系
即百度坐標系,GCJ02坐標系經(jīng)加密后的坐標系。搜狗坐標系、圖吧坐標系等,估計也是在GCJ02基礎(chǔ)上加密而成的。
各主流地圖API采用的坐標系
高德MapABC地圖API 火星坐標
騰訊搜搜地圖API 火星坐標
阿里云地圖API 火星坐標
靈圖51ditu地圖API 火星坐標
百度地圖API 百度坐標
搜狐搜狗地圖API 搜狗坐標
圖吧MapBar地圖API 圖吧坐標
這里介紹幾個常用的在線坐標工具
高德開放平臺
百度拾取坐標系統(tǒng)
在線坐標轉(zhuǎn)換工具
2.各坐標系轉(zhuǎn)換
2.1坐標點實體類
/**
* Description: 坐標點
*
* @author JourWon
* @date Created on 2018年6月19日
*/
public class Point implements Serializable {
private static final long serialVersionUID = 3584864663880053897L;
/**
* 經(jīng)度
*/
private double lng;
/**
* 緯度
*/
private double lat;
2.2各坐標系轉(zhuǎn)換工具類
package com.jourwon.util;
import com.jourwon.pojo.Point;
/**
* Description: 各坐標系之間的轉(zhuǎn)換工具類
*
* @author JourWon
* @date Created on 2018年6月19日
*/
public class CoordinateTransformUtils {
// 圓周率π
private static final double PI = 3.1415926535897932384626D;
// 火星坐標系與百度坐標系轉(zhuǎn)換的中間量
private static final double X_PI = 3.14159265358979324 * 3000.0 / 180.0D;
// Krasovsky 1940
// 長半軸a = 6378245.0, 1/f = 298.3
// b = a * (1 - f)
// 扁率ee = (a^2 - b^2) / a^2;
// 長半軸
private static final double SEMI_MAJOR = 6378245.0D;
// 扁率
private static final double FLATTENING = 0.00669342162296594323D;
// WGS84=>GCJ02 地球坐標系=>火星坐標系
public static Point wgs84ToGcj02(double lng, double lat) {
if (outOfChina(lng, lat)) {
return new Point(lng, lat);
}
double[] offset = offset(lng, lat);
double mglng = lng + offset[0];
double mglat = lat + offset[1];
return new Point(mglng, mglat);
}
// GCJ02=>WGS84 火星坐標系=>地球坐標系(粗略)
public static Point gcj02ToWgs84(double lng, double lat) {
if (outOfChina(lng, lat)) {
return new Point(lng, lat);
}
double[] offset = offset(lng, lat);
double mglng = lng - offset[0];
double mglat = lat - offset[1];
return new Point(mglng, mglat);
}
// GCJ02=>WGS84 火星坐標系=>地球坐標系(精確)
public static Point gcj02ToWgs84Exactly(double lng, double lat) {
if (outOfChina(lng, lat)) {
return new Point(lng, lat);
}
double initDelta = 0.01;
double threshold = 0.000000001;
double dLat = initDelta, dLon = initDelta;
double mLat = lat - dLat, mLon = lng - dLon;
double pLat = lat + dLat, pLon = lng + dLon;
double wgsLat, wgsLng, i = 0;
while (true) {
wgsLat = (mLat + pLat) / 2;
wgsLng = (mLon + pLon) / 2;
Point point = wgs84ToGcj02(wgsLng, wgsLat);
dLon = point.getLng() - lng;
dLat = point.getLat() - lat;
if ((Math.abs(dLat) < threshold) && (Math.abs(dLon) < threshold))
break;
if (dLat > 0)
pLat = wgsLat;
else
mLat = wgsLat;
if (dLon > 0)
pLon = wgsLng;
else
mLon = wgsLng;
if (++i > 10000)
break;
}
return new Point(wgsLng, wgsLat);
}
// GCJ-02=>BD09 火星坐標系=>百度坐標系
public static Point gcj02ToBd09(double lng, double lat) {
double z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * X_PI);
double theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * X_PI);
double bd_lng = z * Math.cos(theta) + 0.0065;
double bd_lat = z * Math.sin(theta) + 0.006;
return new Point(bd_lng, bd_lat);
}
// BD09=>GCJ-02 百度坐標系=>火星坐標系
public static Point bd09ToGcj02(double lng, double lat) {
double x = lng - 0.0065;
double y = lat - 0.006;
double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);
double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI);
double gcj_lng = z * Math.cos(theta);
double gcj_lat = z * Math.sin(theta);
return new Point(gcj_lng, gcj_lat);
}
// WGS84=>BD09 地球坐標系=>百度坐標系
public static Point wgs84ToBd09(double lng, double lat) {
Point point = wgs84ToGcj02(lng, lat);
return gcj02ToBd09(point.getLng(), point.getLat());
}
// BD09=>WGS84 百度坐標系=>地球坐標系
public static Point bd09ToWgs84(double lng, double lat) {
Point point = bd09ToGcj02(lng, lat);
return gcj02ToWgs84(point.getLng(), point.getLat());
}
/**
* Description: 中國境外返回true,境內(nèi)返回false
* @param lng 經(jīng)度
* @param lat 緯度
* @return
*/
public static boolean outOfChina(double lng, double lat) {
if (lng < 72.004 || lng > 137.8347)
return true;
if (lat < 0.8293 || lat > 55.8271)
return true;
return false;
}
// 經(jīng)度偏移量
private static double transformLng(double lng, double lat) {
double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
return ret;
}
// 緯度偏移量
private static double transformLat(double lng, double lat) {
double ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat
+ 0.2 * Math.sqrt(Math.abs(lng));
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
return ret;
}
// 偏移量
public static double[] offset(double lng, double lat) {
double[] lngLat = new double[2];
double dlng = transformLng(lng - 105.0, lat - 35.0);
double dlat = transformLat(lng - 105.0, lat - 35.0);
double radlat = lat / 180.0 * PI;
double magic = Math.sin(radlat);
magic = 1 - FLATTENING * magic * magic;
double sqrtmagic = Math.sqrt(magic);
dlng = (dlng * 180.0) / (SEMI_MAJOR / sqrtmagic * Math.cos(radlat) * PI);
dlat = (dlat * 180.0) / ((SEMI_MAJOR * (1 - FLATTENING)) / (magic * sqrtmagic) * PI);
lngLat[0] = dlng;
lngLat[1] = dlat;
return lngLat;
}
}
3.測試
/**
* Description: 坐標系轉(zhuǎn)換工具測試類
*
* @author JourWon
* @date Created on 2018年6月19日
*/
public class CoordinateTransformUtilsTest {
/**
* Description: 地球坐標系 =>火星坐標系、百度坐標系
*/
@Test
public void test01() {
// 廣州市中大地鐵站
Point point = new Point(113.28749670783887D, 23.094783676708065D);
System.out.println("地球坐標系 : " + point);
Point wgs84ToGcj02 = CoordinateTransformUtils.wgs84ToGcj02(point.getLng(), point.getLat());
System.out.println("火星坐標系 : " + wgs84ToGcj02);
Point wgs84ToBd09 = CoordinateTransformUtils.wgs84ToBd09(point.getLng(), point.getLat());
System.out.println("百度坐標系 : " + wgs84ToBd09);
}
/**
* Description: 火星坐標系=>地球坐標系、百度坐標系
*/
@Test
public void test02() {
// 廣州市珠江新城地鐵站
Point point = new Point(113.321171D, 23.119285D);
System.out.println("火星坐標系 : " + point);
Point wgs84ToGcj02 = CoordinateTransformUtils.gcj02ToWgs84(point.getLng(), point.getLat());
System.out.println("地球坐標系 : " + wgs84ToGcj02);
Point wgs84ToBd09 = CoordinateTransformUtils.gcj02ToBd09(point.getLng(), point.getLat());
System.out.println("百度坐標系 : " + wgs84ToBd09);
}
/**
* Description: 百度坐標系=>地球坐標系、火星坐標系
*/
@Test
public void test03() {
// 廣州市體育西路地鐵站
Point point = new Point(113.328035D, 23.136929D);
System.out.println("百度坐標系 : " + point);
Point wgs84ToGcj02 = CoordinateTransformUtils.bd09ToWgs84(point.getLng(), point.getLat());
System.out.println("地球坐標系 : " + wgs84ToGcj02);
Point wgs84ToBd09 = CoordinateTransformUtils.bd09ToGcj02(point.getLng(), point.getLat());
System.out.println("火星坐標系 : " + wgs84ToBd09);
}
}
完整代碼下載鏈接
百度坐標要先轉(zhuǎn)GCJ-02,之后再轉(zhuǎn)WGS84
(1)WGS84:表示GPS獲取的坐標;
(2)GCJ02:是由中國國家測繪局制訂的地理信息系統(tǒng)的坐標系統(tǒng)。由WGS84坐標系經(jīng)加密后的坐標系;文章來源:http://www.zghlxwxcb.cn/news/detail-665531.html
(3)BD09:為百度坐標系,在GCJ02坐標系基礎(chǔ)上再次加密。其中BD09II表示百度經(jīng)緯度坐標,BD09MC表示百度墨卡托米制坐標。文章來源地址http://www.zghlxwxcb.cn/news/detail-665531.html
public class Transform {
double x_PI = 3.14159265358979324 * 3000.0 / 180.0;
double PI = 3.1415926535897932384626;
double a = 6378245.0;
double ee = 0.00669342162296594323;
/**
* 百度坐標系 (BD-09) 與 火星坐標系 (GCJ-02)的轉(zhuǎn)換
* 即 百度 轉(zhuǎn) 谷歌、高德
* @param bd_lon
* @param bd_lat
* @returns {*[]}
*/
public Point bd09togcj02(double bd_lon, double bd_lat){
double x = bd_lon - 0.0065;
double y = bd_lat - 0.006;
double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_PI);
double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_PI);
double gg_lng = z * Math.cos(theta);
double gg_lat = z * Math.sin(theta);
Point point=new Point(gg_lng, gg_lat);
return point;
}
/**
* 火星坐標系 (GCJ-02) 與百度坐標系 (BD-09) 的轉(zhuǎn)換
* 即谷歌、高德 轉(zhuǎn) 百度
* @param lng
* @param lat
* @returns {*[]}
*/
public Point gcj02tobd09(double lng, double lat){
double z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
double theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
double bd_lng = z * Math.cos(theta) + 0.0065;
double bd_lat = z * Math.sin(theta) + 0.006;
Point point=new Point(bd_lng, bd_lat);
return point;
};
/**
* WGS84轉(zhuǎn)GCj02
* @param lng
* @param lat
* @returns {*[]}
*/
public Point wgs84togcj02(double lng, double lat){
double dlat = transformlat(lng - 105.0, lat - 35.0);
double dlng = transformlng(lng - 105.0, lat - 35.0);
double radlat = lat / 180.0 * PI;
double magic = Math.sin(radlat);
magic = 1 - ee * magic * magic;
double sqrtmagic = Math.sqrt(magic);
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
double mglat = lat + dlat;
double mglng = lng + dlng;
Point point=new Point(mglng, mglat);
return point;
};
/**
* GCJ02 轉(zhuǎn)換為 WGS84
* @param lng
* @param lat
* @returns {*[]}
*/
public Point gcj02towgs84(double lng, double lat){
double dlat = transformlat(lng - 105.0, lat - 35.0);
double dlng = transformlng(lng - 105.0, lat - 35.0);
double radlat = lat / 180.0 * PI;
double magic = Math.sin(radlat);
magic = 1 - ee * magic * magic;
double sqrtmagic = Math.sqrt(magic);
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
double mglat = lat + dlat;
double mglng = lng + dlng;
Point point=new Point(mglng, mglat);
return point;
};
private double transformlat(double lng,double lat){
double ret= -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
return ret;
}
private double transformlng(double lng,double lat){
double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
return ret;
}
}
到了這里,關(guān)于WGS84地球坐標系,GCJ02火星坐標系,BD09百度坐標系簡介與轉(zhuǎn)換 資料收集的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!