gpt4 book ai didi

ios - 在 iOS 中位置之间的距离错误?

转载 作者:行者123 更新时间:2023-11-28 22:17:11 25 4
gpt4 key购买 nike

您好,您的目标是使用以下方法找出我当前位置与存储在 NSMutableArray 值中的位置(纬度和经度)之间的距离。

但是距离不对..请帮忙..

我的代码

    -(void)getDistancetoShow:(NSMutableArray *)newArray{

CLLocationCoordinate2D coordinateUser = [self getLocation];


float _lat,_long;


first_Loc = [[CLLocation alloc] initWithLatitude:coordinateUser.latitude longitude:coordinateUser.longitude];

for(int p=0;p<[[newArray1 valueForKey:@"Name"] count];p++){

_lat=[[[newArray1 valueForKey:@"Latitude"] objectAtIndex:p]floatValue];
_long=[[[newArray1 valueForKey:@"Longitude"] objectAtIndex:p]floatValue];
second_loc=[[CLLocation alloc] initWithLatitude:_lat longitude:_long];


showDistance=[second_loc distanceFromLocation:first_Loc]/1000;

[distanceToDispaly addObject:[NSString stringWithFormat:@"%.2f KM",showDistance]];
}

NSLog(@"first=%@, second=%@", first_Loc, second_loc);


}

数组中的纬度

( "47.0735010448824", "47.0564688100431", "47.0582514311038", "47.0587640538326", "47.0569233603454", "47.0541853132569", "47.0542029215138", "47.0544259594592", "47.0560264547367", "47.0576532159776", "47.0550023679218", "47.0342030007379", "47.0746263896213", "47.0740256635512", "47.0524765957921", "47.0606287049051", "47.0539691521825", "47.0542799159057", "47.0651001682846", "47.0536948902097", "47.0525973335309", "47.0389265414812", "47.0761811267051", "47.0668801601942", "47.0614859079241", "47.0579433468181", “47.0718998779465”)

数组中的经度

( "21.9154175327011", "21.9312065669748", "21.9337414545594", "21.9346772505188", "21.9300587945685", "21.9363460105132", "21.9362081709222", "21.9343042603097", "21.939485335992", "21.9320057169724", "21.9300799002643", "21.9485373571669", "21.9310667367526", "21.9318507902135", "21.9192195298473", "21.9195273899529", "21.9329595191441", "21.9292015418841", "21.9219452321208", "21.9098849252041", "21.9074768948561", "21.9424499491422", "21.9151458954504", "21.9304346568769", "21.9305973807911", "21.9331511189507", “21.9159872752442”)

但真正的距离是用 9**** 凝视,但现在 5***

最佳答案

CLLocation 为您提供两地之间的直线距离。我认为您正在拉开乌鸦距离。

首先取两个地方的坐标,求出它们之间的距离。然后搜索这两个坐标之间的乌鸦距离。

希望对你有帮助

关于ios - 在 iOS 中位置之间的距离错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21375101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com