用墨卡托和GPS坐标计算距离时误差测试

iOS墨卡托和GPS坐标计算距离时误差测试,测试结果:

  • 墨卡托和gps坐标来回转换没有误差。
  • 墨卡托坐标计算出的距离比gps坐标计算出的距离大,100/92*100 = 108米,每100米多算出8米。
  • 故随着导航距离缩短,误差会逐渐变小。

log

25.780135+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 10.00
25.781216+0800 gps_mktDistanceTest[91276:1928266] gps dis = 9.20
25.781387+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12624927.127331,2653334.851787
25.781531+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12624927.127331,2653334.851787
25.781669+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 20.00
25.781805+0800 gps_mktDistanceTest[91276:1928266] gps dis = 18.40
25.781952+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12624937.127331,2653334.851787
25.782072+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12624937.127331,2653334.851787
25.782184+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 30.00
25.782318+0800 gps_mktDistanceTest[91276:1928266] gps dis = 27.59
25.782418+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12624947.127331,2653334.851787
25.782547+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12624947.127331,2653334.851787
25.785722+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 40.00
25.785817+0800 gps_mktDistanceTest[91276:1928266] gps dis = 36.79
25.785952+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12624957.127331,2653334.851787
25.786067+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12624957.127331,2653334.851787
25.786170+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 50.00
25.786280+0800 gps_mktDistanceTest[91276:1928266] gps dis = 45.99
25.786379+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12624967.127331,2653334.851787
25.786473+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12624967.127331,2653334.851787
25.786561+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 60.00
25.786626+0800 gps_mktDistanceTest[91276:1928266] gps dis = 55.19
25.786718+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12624977.127331,2653334.851787
25.786878+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12624977.127331,2653334.851787
25.787094+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 70.00
25.787273+0800 gps_mktDistanceTest[91276:1928266] gps dis = 64.38
25.787465+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12624987.127331,2653334.851787
25.787647+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12624987.127331,2653334.851787
25.787853+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 80.00
25.788050+0800 gps_mktDistanceTest[91276:1928266] gps dis = 73.58
25.788224+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12624997.127331,2653334.851787
25.788399+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12624997.127331,2653334.851787
25.788586+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 90.00
25.788826+0800 gps_mktDistanceTest[91276:1928266] gps dis = 82.78
25.789067+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12625007.127331,2653334.851787
25.789287+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12625007.127331,2653334.851787
25.789430+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 100.00
25.789628+0800 gps_mktDistanceTest[91276:1928266] gps dis = 91.98
25.789865+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12625017.127331,2653334.851787
25.790090+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12625017.127331,2653334.851787
25.790289+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 110.00
25.790511+0800 gps_mktDistanceTest[91276:1928266] gps dis = 101.18
25.790775+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12625027.127331,2653334.851787
25.791032+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12625027.127331,2653334.851787
25.791194+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 120.00
25.791390+0800 gps_mktDistanceTest[91276:1928266] gps dis = 110.37
25.791586+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12625037.127331,2653334.851787
25.791812+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12625037.127331,2653334.851787
25.791985+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 130.00
25.792163+0800 gps_mktDistanceTest[91276:1928266] gps dis = 119.57
25.792457+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12625047.127331,2653334.851787
25.792679+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12625047.127331,2653334.851787
25.792808+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 140.00
25.793005+0800 gps_mktDistanceTest[91276:1928266] gps dis = 128.77
25.793225+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12625057.127331,2653334.851787
25.793416+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12625057.127331,2653334.851787
25.793572+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 150.00
25.793735+0800 gps_mktDistanceTest[91276:1928266] gps dis = 137.97
25.793928+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12625067.127331,2653334.851787
25.794105+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12625067.127331,2653334.851787
25.794290+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 160.00
25.794419+0800 gps_mktDistanceTest[91276:1928266] gps dis = 147.16
25.794611+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12625077.127331,2653334.851787
25.794792+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12625077.127331,2653334.851787
25.794965+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 170.00
25.795133+0800 gps_mktDistanceTest[91276:1928266] gps dis = 156.36
25.795327+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12625087.127331,2653334.851787
25.795490+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12625087.127331,2653334.851787
25.795654+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 180.00
25.795776+0800 gps_mktDistanceTest[91276:1928266] gps dis = 165.56
25.795974+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12625097.127331,2653334.851787
25.796177+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12625097.127331,2653334.851787
25.796311+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 190.00
25.796474+0800 gps_mktDistanceTest[91276:1928266] gps dis = 174.76
25.796658+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12625107.127331,2653334.851787
25.796823+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12625107.127331,2653334.851787
25.796981+0800 gps_mktDistanceTest[91276:1928266] mkt dis = 200.00
25.797129+0800 gps_mktDistanceTest[91276:1928266] gps dis = 183.96
25.797310+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换前12625117.127331,2653334.851787
25.797474+0800 gps_mktDistanceTest[91276:1928266] 墨卡托坐标 转换后12625117.127331,2653334.851787

code

//
//  ViewController.m
//  gps_mktDistanceTest
//
#import "ViewController.h"
#import "HTCoorTransformEach/HTCoorTransforEach.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];

}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    for (int i = 1; i <= 20; ++i) {
        //mkt计算距离
        double x0 = 12624917.12733079;
        double y0 = 2653334.851787222;

        double x1 = x0 + 10 * i;
        double y1 = y0;

        double dis1 = sqrt(pow(x1 - x0, 2) + pow(y1 - y0, 2));
        NSLog(@"mkt dis = %.2f", dis1);

        //gps计算距离
        HTMktCoor lCoor = {x0, y0};

        CLLocationCoordinate2D lGPS0 = [HTCoorTransforEach Mercator2WorldGS:lCoor];
        CLLocation *lLoc0 = [[CLLocation alloc] initWithLatitude:lGPS0.latitude longitude:lGPS0.longitude];

        HTMktCoor lCoor1 = {x1, y1};
        CLLocationCoordinate2D lGPS1 = [HTCoorTransforEach Mercator2WorldGS:lCoor1];
        CLLocation *lLoc1 = [[CLLocation alloc] initWithLatitude:lGPS1.latitude longitude:lGPS1.longitude];

       HTMktCoor lMkt = [HTCoorTransforEach WorldGS2Mercator:lGPS1];
        double gpsDis = [lLoc0 distanceFromLocation:lLoc1];
        NSLog(@"gps dis = %.2f", gpsDis);

        NSLog(@"墨卡托坐标 转换前%f,%f", x1, y1);
        NSLog(@"墨卡托坐标 转换后%f,%f", lMkt.x, lMkt.y);
    }
}

@end
//
//  HTCoorTransfor.h
//
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
typedef struct{

    ///墨卡托x坐标,对应经纬度中的经度
    double x;

    ///墨卡托y坐标,对应经纬度中的纬度
    double y;
}HTMktCoor;
NS_ASSUME_NONNULL_BEGIN
@interface HTCoorTransforEach : NSObject
//WGS-84 坐标转换成 墨卡托 坐标
+ (HTMktCoor)WorldGS2Mercator:(CLLocationCoordinate2D)coordinate;
//墨卡托 坐标转换成 WGS-84 坐标
+ (CLLocationCoordinate2D)Mercator2WorldGS:(HTMktCoor)mercator;
@end
NS_ASSUME_NONNULL_END

//
//  HTCoorTransfor.m
//
#import "HTCoorTransforEach.h"
@implementation HTCoorTransforEach
//WGS-84 坐标转换成 墨卡托 坐标。警告:墨卡托的x对应经度longtitude,y对应纬度latitude,千万别搞反了!
+ (HTMktCoor)WorldGS2Mercator:(CLLocationCoordinate2D)coordinate
{
    double lon = coordinate.longitude*20037508.34/180;
    double lat = log(tan((90+coordinate.latitude)*M_PI/360))/(M_PI/180);
    lat = lat*20037508.34/180;

    HTMktCoor lCoor;
    lCoor.x = lon;
    lCoor.y = lat;
    return lCoor;
}
//墨卡托 坐标转换成 WGS-84 坐标。警告:墨卡托的x对应经度longtitude,y对应纬度latitude,千万别搞反了!
+ (CLLocationCoordinate2D)Mercator2WorldGS:(HTMktCoor)mercator
{
    double lon = mercator.x/20037508.34*180;
    double lat = mercator.y/20037508.34*180;
    lat = 180/M_PI*(2*atan(exp(lat*M_PI/180))-M_PI/2);
    return CLLocationCoordinate2DMake(lat, lon);
}
@end

原文地址:https://www.cnblogs.com/Dast1/p/11271428.html

时间: 2024-10-25 20:50:25

用墨卡托和GPS坐标计算距离时误差测试的相关文章

计算两个GPS坐标的距离

场景:已知两个GPS点的经纬度坐标信息.计算两点的距离. 1. 距离/纬度关系 GPS: 22.514519,113.380301 GPS: 22.511962,113.380301 距离: 284.6439379583341   jl_wd=284.6439379583341/(22.51451-22.511962) = 111712.69150641055729984301412873 (米/度) 2. 距离/经度关系 GPS: 22.514866, 113.388444 GPS: 22.5

【转】通过经纬度坐标计算距离的方法(经纬度距离计算)

最近在网上搜索“通过经纬度坐标计算距离的方法”,发现网上大部分都是如下的代码: #define PI 3.14159265 static double Rc = 6378137;  // 赤道半径 static double Rj = 6356725;  // 极半径 class JWD { public: double m_Longitude, m_Latitude; double m_RadLo, m_RadLa; double Ec; double Ed; public: JWD(doub

Android给定坐标计算距离

给定两点的经纬度.计算两点之间的距离.这里要注意经纬度一定要依照顺序填写 1. 利用android中的工具获得,单位是米 float[] results=new float[1]; Location.distanceBetween(latitude,longitude,Double.parseDouble(lat), Double.parseDouble(lng),results); Log.i("距离", results[0]+""); 2. 通过计算的方式获得,

Java 根据两个经纬度坐标计算距离

public class Distance{    private static final double EARTH_RADIUS = 6378137;    private static double rad(double d)    {       return d * Math.PI / 180.0;    }        /**     * 根据两点间经纬度坐标(double值),计算两点间距离,单位为米     * @param lng1     * @param lat1    

通过经纬度坐标计算距离的方法(经纬度距离计算)

http://home.juedui100.com/user/23468184.htmlhttp://home.juedui100.com/user/23771088.htmlhttp://home.juedui100.com/user/24018651.htmlhttp://home.juedui100.com/user/23875372.htmlhttp://home.juedui100.com/user/23874288.htmlhttp://home.juedui100.com/user

PHP根据两个经纬度坐标计算距离

function radian($d) {             $d * 3.1415926535898 / 180.0;   } function distance_calculate($longitude1, $latitude1, $longitude2, $latitude2) {             $radLat1 = adian ( $latitude1 );             $radLat2 = radian ( $latitude2 );            

sql 坐标距离排序计算距离(转)

如果两个坐标的列是(x1,y1).(x2,y2),那么他们之间的距离:SQRT((X1-X2)*(X1-X2)+(Y1-Y2)*(Y1-Y2)) sql排序 SELECT * FROM m_store ORDER BY SQRT((121.517759-`longitude`)*(121.517759-`longitude`)+(31.178469-`latitude`)*(31.178469-`latitude`)) PHP计算距离 /***求两个已知经纬度之间的距离,单位为米*@param

ios根据gps坐标来计算两点间的距离

//ios根据gps坐标来计算两点间的距离 //x1,y1 点1的坐标 x2,y2点2的坐标 -(double) gps2m:(double)x1 _y1:(double)y1 _x2:(double)x2 _y2:(double)y2{ double radLat1 = (x1 * 3.1416 / 180.0); double radLat2 = (x2 * 3.1416 / 180.0); double a = radLat1 - radLat2; double b = (y1 - y2)

计算两个GPS坐标点的距离

计算两个GPS坐标点的距离,第一个参数是第一个点的维度,第二个参数是第一个点的经度 http://yuninglovekefan.blog.sohu.com/235655696.html /** * */ package utils; /** * 坐标计算的工具类 * * @author ywf * */ public class PositionUtils { private static final double EARTH_RADIUS = 6371.004; static double