百度地图坐标系和火星坐标系之间的互相转换

// 百度转火星

-(CLLocationCoordinate2D)hhTrans_GCGPS:(CLLocationCoordinate2D)baiduGps

{

    

    CLLocationCoordinate2D googleGps;

    

    double bd_x=baiduGps.longitude - 0.0065;

    

    double bd_y=baiduGps.latitude - 0.006;

    

    double z = sqrt(bd_x * bd_x + bd_y * bd_y) - 0.00002 * sin(bd_y * M_PI);

    

    double theta = atan2(bd_y, bd_x) - 0.000003 * cos(bd_x * M_PI);

    

    googleGps.longitude = z * cos(theta);

    

    googleGps.latitude = z * sin(theta);

    

    return googleGps;

    

}

其他坐标转百度坐标系

 CLLocationCoordinate2D test = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude);

        //转换 google地图、soso地图、aliyun地图、mapabc地图和amap地图所用坐标至百度坐标

        NSDictionary* testdic = BMKConvertBaiduCoorFrom(test,BMK_COORDTYPE_COMMON);

        //转换GPS坐标至百度坐标

        testdic = BMKConvertBaiduCoorFrom(test,BMK_COORDTYPE_GPS);

        NSLog(@"x=%f,y=%f",location.coordinate.latitude,location.coordinate.longitude);

        NSLog(@"x=%@,y=%@",[testdic objectForKey:@"x"],[testdic objectForKey:@"y"]);

        NSString *lat = [MCEncryption base64FromBase64String:[testdic objectForKey:@"x"]] ;

        NSString *lon = [MCEncryption base64FromBase64String:[testdic objectForKey:@"y"]] ;

转载于:https://www.cnblogs.com/mglttkx/p/5522856.html

package com.map; public class GPSConverterUtils { public static final String BAIDU_LBS_TYPE = "bd09ll"; public static double pi = 3.1415926535897932384626; public static double a = 6378245.0; public static double ee = 0.00669342162296594323; /** * 84 to 火星坐标系 (GCJ-02) World Geodetic System ==> Mars Geodetic System * 天地图火星 * @param lat * @param lon */ public static GPS gps84_To_Gcj02(double lat, double lon) { if (outOfChina(lat, lon)) { return null; } double dLat = transformLat(lon - 105.0, lat - 35.0); double dLon = transformLon(lon - 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); dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi); double mgLat = lat + dLat; double mgLon = lon + dLon; return new GPS(mgLat, mgLon); } /** * * 火星坐标系 (GCJ-02) to 84 * * @param lon * @param lat * @return *火星转天地图 */ public static GPS gcj_To_Gps84(double lat, double lon) { GPS gps = transform(lat, lon); double lontitude = lon * 2 - gps.getLon(); double latitude = lat * 2 - gps.getLat(); return new GPS(latitude, lontitude); } /** * 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法 将 GCJ-02 坐标转换成 BD-09 坐标 *火星转百度 * @param gg_lat * @param gg_lon */ public static GPS gcj02_To_Bd09(double gg_lat, double gg_lon) { double x = gg_lon, y = gg_lat; double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * pi); double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * pi); double bd_lon = z * Math.cos(theta) + 0.0065; double bd_lat = z * Math.sin(theta) + 0.006;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值