一、集成百度地圖的 SDK
最近項目中需要集成百度地圖的 SDK,但是設置完畢後發現在 Xcode7 中真機調試一直出現靜態庫報錯的問題
可是用終端查看支持的系統架構也是含有當前類型的
架構補充:
//模擬器架構: i386 / x86_64
//真機架構: armv7/armv7s/arm64
在 Xcode7 中模擬器正常。相同的項目改用 Xcode6.4 打開真機調試完全沒有問題,前段時間發現 Xcode7 雖然對自身的庫做了一些變化,難道第三方的也會出現不兼容的情況?在網上找了一部分資料發現是 Bitcode 這個配置的問題(詳細瞭解Bitcode請點擊這裏傳送門),在項目中做如下修改 Xcode7 真機調試正常:
二、經緯度座標系
1:各家地圖標準
API | 座標系 |
百度地圖API | 百度座標* |
騰訊搜搜地圖API | 火星座標 |
搜狐搜狗地圖API | 搜狗座標* |
阿里雲地圖API | 火星座標 |
圖吧MapBar地圖API | 圖吧座標* |
高德MapABC地圖API | 火星座標 |
靈圖51ditu地圖API | 火星座標 |
2:百度座標爲何有偏移
國際經緯度座標標準爲WGS-84,國內必須至少使用國測局制定的GCJ-02,對地理位置進行首次加密。百度座標在此基礎上,進行了BD-09二次加密措施,更加保護了個人隱私。百度對外接口的座標系並不是GPS採集的真實經緯度,需要通過座標轉換接口進行轉換。
3:百度座標BD-09與火星座標GCJ-02的互相轉換
在百度地圖 SDK 中包含了將火星座標轉換爲百度座標的接口:
/// 將原始GPS座標轉換爲百度座標
+ (CLLocationCoordinate2D)changeGPSCoordinateToBaidu:(CLLocationCoordinate2D)coordinate {
NSDictionary *base64dic = BMKConvertBaiduCoorFrom(coordinate,BMK_COORDTYPE_GPS);
CLLocationCoordinate2D coordinateOfBaidu = BMKCoorDictionaryDecode(base64dic);
// NSLog(@"x=%lf,y=%lf",coordinate.latitude,coordinate.longitude);
// NSLog(@"x=%lf,y=%lf",coordinateOfBaidu.latitude,coordinateOfBaidu.longitude);
return coordinateOfBaidu;
}
/// 將google座標,51地圖座標,mapabc座標轉換爲百度座標
+ (CLLocationCoordinate2D)changeCOMMONCoordinateToBaidu:(CLLocationCoordinate2D)coordinate {
NSDictionary *base64dic = BMKConvertBaiduCoorFrom(coordinate,BMK_COORDTYPE_COMMON);
CLLocationCoordinate2D coordinateOfBaidu = BMKCoorDictionaryDecode(base64dic);
// NSLog(@"x=%lf,y=%lf",coordinate.latitude,coordinate.longitude);
// NSLog(@"x=%lf,y=%lf",coordinateOfBaidu.latitude,coordinateOfBaidu.longitude);
return coordinateOfBaidu;
}
但是有時候我們還是需要將百度座標轉換成火星座標以便調用原生的地圖或者其它地圖應用,現貼出 OC 的轉換代碼如下:
/// 將火星座標轉換爲百度座標
+ (CLLocationCoordinate2D)changeCOMMONCoordinateToBaidu:(CLLocationCoordinate2D)coordinate {
double PI = 3.14159265358979324 * 3000.0 / 180.0;
double longitude = coordinate.longitude;
double latitude = coordinate.latitude;
double parameter = sqrt(longitude * longitude + latitude * latitude) + 0.00002 * sin(latitude * PI);
double theta = atan2(latitude, longitude) + 0.000003 * cos(longitude * PI);
double Baidu_longitude = parameter * cos(theta) + 0.0065;
double Baidu_latitude = parameter * sin(theta)+ 0.006;
CLLocationCoordinate2D Baidu_Coordinate = CLLocationCoordinate2DMake(Baidu_latitude, Baidu_longitude);
return Baidu_Coordinate;
}
/// 將百度座標轉換爲火星座標
+ (CLLocationCoordinate2D)changeBaiduCoordinateToCOMMON:(CLLocationCoordinate2D)coordinate {
double PI = 3.14159265358979324 * 3000.0 / 180.0;
double longitude = coordinate.longitude - 0.0065;
double latitude = coordinate.latitude - 0.006;
double parameter = sqrt(longitude * longitude + latitude * latitude) - 0.00002 * sin(latitude * PI);
double theta = atan2(latitude, longitude) - 0.000003 * cos(longitude * PI);
double COMMON_longitude = parameter * cos(theta);
double COMMON_latitude = parameter * sin(theta);
CLLocationCoordinate2D COMMON_Coordinate = CLLocationCoordinate2DMake(COMMON_latitude, COMMON_longitude);
return COMMON_Coordinate;
}
參考鏈接:
http://www.jianshu.com/p/3e1b4e2d06c6
http://www.tekuba.net/program/364/
http://www.cnblogs.com/jay-dong/archive/2013/03/13/2957648.html