gpt4 book ai didi

ios - 如何计算CLLocationDistance的中心坐标

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:54:39 25 4
gpt4 key购买 nike

我想计算我的位置和一些注释之间的中心点。到目前为止,我已经这样做了:

CLLocation *myLoc = self.locMgr.location;

MKPointAnnotation *middleAnnotation = [locationV.annotations objectAtIndex:locationV.annotations.count/2];

CLLocation *someStuiodLoc = [[CLLocation alloc] initWithLatitude:middleAnnotation.coordinate.latitude longitude:middleAnnotation.coordinate.longitude];

CLLocationDistance dist = [myLoc distanceFromLocation:someStuiodLoc];

如何计算“dist”的中心点/坐标??

最佳答案

#define ToRadian(x) ((x) * M_PI/180)
#define ToDegrees(x) ((x) * 180/M_PI)

+ (CLLocationCoordinate2D)midpointBetweenCoordinate:(CLLocationCoordinate2D)c1 andCoordinate:(CLLocationCoordinate2D)c2
{
c1.latitude = ToRadian(c1.latitude);
c2.latitude = ToRadian(c2.latitude);
CLLocationDegrees dLon = ToRadian(c2.longitude - c1.longitude);
CLLocationDegrees bx = cos(c2.latitude) * cos(dLon);
CLLocationDegrees by = cos(c2.latitude) * sin(dLon);
CLLocationDegrees latitude = atan2(sin(c1.latitude) + sin(c2.latitude), sqrt((cos(c1.latitude) + bx) * (cos(c1.latitude) + bx) + by*by));
CLLocationDegrees longitude = ToRadian(c1.longitude) + atan2(by, cos(c1.latitude) + bx);

CLLocationCoordinate2D midpointCoordinate;
midpointCoordinate.longitude = ToDegrees(longitude);
midpointCoordinate.latitude = ToDegrees(latitude);

return midpointCoordinate;
}

关于ios - 如何计算CLLocationDistance的中心坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16850332/

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