25.780135+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 10.0025.781216+0800 gps_mktdistanceTest[91276:1928266] gps dis = 9.2025.781387+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12624927.127331,2653334.85178725.781531+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12624927.127331,2653334.85178725.781669+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 20.0025.781805+0800 gps_mktdistanceTest[91276:1928266] gps dis = 18.4025.781952+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12624937.127331,2653334.85178725.782072+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12624937.127331,2653334.85178725.782184+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 30.0025.782318+0800 gps_mktdistanceTest[91276:1928266] gps dis = 27.5925.782418+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12624947.127331,2653334.85178725.782547+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12624947.127331,2653334.85178725.785722+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 40.0025.785817+0800 gps_mktdistanceTest[91276:1928266] gps dis = 36.7925.785952+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12624957.127331,2653334.85178725.786067+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12624957.127331,2653334.85178725.786170+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 50.0025.786280+0800 gps_mktdistanceTest[91276:1928266] gps dis = 45.9925.786379+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12624967.127331,2653334.85178725.786473+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12624967.127331,2653334.85178725.786561+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 60.0025.786626+0800 gps_mktdistanceTest[91276:1928266] gps dis = 55.1925.786718+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12624977.127331,2653334.85178725.786878+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12624977.127331,2653334.85178725.787094+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 70.0025.787273+0800 gps_mktdistanceTest[91276:1928266] gps dis = 64.3825.787465+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12624987.127331,2653334.85178725.787647+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12624987.127331,2653334.85178725.787853+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 80.0025.788050+0800 gps_mktdistanceTest[91276:1928266] gps dis = 73.5825.788224+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12624997.127331,2653334.85178725.788399+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12624997.127331,2653334.85178725.788586+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 90.0025.788826+0800 gps_mktdistanceTest[91276:1928266] gps dis = 82.7825.789067+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12625007.127331,2653334.85178725.789287+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12625007.127331,2653334.85178725.789430+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 100.0025.789628+0800 gps_mktdistanceTest[91276:1928266] gps dis = 91.9825.789865+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12625017.127331,2653334.85178725.790090+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12625017.127331,2653334.85178725.790289+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 110.0025.790511+0800 gps_mktdistanceTest[91276:1928266] gps dis = 101.1825.790775+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12625027.127331,2653334.85178725.791032+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12625027.127331,2653334.85178725.791194+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 120.0025.791390+0800 gps_mktdistanceTest[91276:1928266] gps dis = 110.3725.791586+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12625037.127331,2653334.85178725.791812+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12625037.127331,2653334.85178725.791985+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 130.0025.792163+0800 gps_mktdistanceTest[91276:1928266] gps dis = 119.5725.792457+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12625047.127331,2653334.85178725.792679+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12625047.127331,2653334.85178725.792808+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 140.0025.793005+0800 gps_mktdistanceTest[91276:1928266] gps dis = 128.7725.793225+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12625057.127331,2653334.85178725.793416+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12625057.127331,2653334.85178725.793572+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 150.0025.793735+0800 gps_mktdistanceTest[91276:1928266] gps dis = 137.9725.793928+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12625067.127331,2653334.85178725.794105+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12625067.127331,2653334.85178725.794290+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 160.0025.794419+0800 gps_mktdistanceTest[91276:1928266] gps dis = 147.1625.794611+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12625077.127331,2653334.85178725.794792+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12625077.127331,2653334.85178725.794965+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 170.0025.795133+0800 gps_mktdistanceTest[91276:1928266] gps dis = 156.3625.795327+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12625087.127331,2653334.85178725.795490+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12625087.127331,2653334.85178725.795654+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 180.0025.795776+0800 gps_mktdistanceTest[91276:1928266] gps dis = 165.5625.795974+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12625097.127331,2653334.85178725.796177+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12625097.127331,2653334.85178725.796311+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 190.0025.796474+0800 gps_mktdistanceTest[91276:1928266] gps dis = 174.7625.796658+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12625107.127331,2653334.85178725.796823+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换后12625107.127331,2653334.85178725.796981+0800 gps_mktdistanceTest[91276:1928266] mkt dis = 200.0025.797129+0800 gps_mktdistanceTest[91276:1928266] gps dis = 183.9625.797310+0800 gps_mktdistanceTest[91276:1928266] 墨卡托坐标 转换前12625117.127331,2653334.85178725.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,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;@endNS_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
总结 以上是内存溢出为你收集整理的用墨卡托和GPS坐标计算距离时误差测试全部内容,希望文章能够帮你解决用墨卡托和GPS坐标计算距离时误差测试所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)