如果Android、iOS都是同一个服务器,需要两个平台数据一致,但是百度、高德在国外不行,谷歌国内又不能用,微软bing地图的sdk有好几年没更新了。用系统自带的定位,用百度地图显示,再用百度地图定位,两个的误差超过1公里。
不用相同的地图,定位一样,地图数据不一样,所以需要集成两个地图的sdk,国内用高德,国外用谷歌,系统自带定位需要进行火星定位矫正,才能在国内正确使用。
所以要先判定是国内还是国外,再来相互转换不同标准坐标系:https://github.com/TinyQ/TQLocationConverter
//我是个经纬度 CLLocationCoordinate2D location = (CLLocationCoordinate2D){ .latitude = 0.0, .longitude = 0.0 }; //判断是否在中国 if ([TQLocationConverter isLocationOutOfChina:location]) { //将WGS-84转为GCJ-02(火星坐标) location = [TQLocationConverter transformFromWGSToGCJ:location]; //将GCJ-02(火星坐标)转为百度坐标 location = [TQLocationConverter transformFromGCJToBaidu:location]; //将百度坐标转为GCJ-02(火星坐标) location = [TQLocationConverter transformFromBaiduToGCJ:location]; //将GCJ-02(火星坐标)转为WGS-84 location = [TQLocationConverter transformFromGCJToWGS:location]; } NSLog(@"%f,%f",location.latitude,location.longitude);