Tag: cllocationdistance

MKMapView获取自定义路线上的坐标之间的距离

我有一个自定义的路线在地图上,并希望得到MKMapView上的两个坐标之间的距离。 以下是我迄今为止所做的步骤… 我已经抓住了坐标点并准备了一个CLLocationCoordinate2D数组(像customRoute = [CLLocationCoordinate2D] )。 为了显示路线,使用坐标数组,我使用MKOverlay方法绘制了MKPolyline 。 并使用distanceFromLocation方法计算两个坐标之间的distanceFromLocation 。 当我计算距离时,得到的距离是直线距离,但不是基于方向。 可以说,用户在位置A(在自定义路线上)并且想要到达位置B(在自定义路线上)。 所以我想要计算的是A和B之间的距离(不是直线距离)。 现在我正在从用户位置找出最近的坐标,并通过循环坐标数组来计算到目的地的距离。 但是,如果有多条路线,而最近的点位于另一条路线上,则不会给出正确的结果。 我想到的一件事是在地图上设置自定义方向,并find距离,但我不知道如何实现这一目标。 正在使用的语言是Swift。 任何forms的帮助/build议非常感谢。

从用户位置查找最接近的经度和纬度

我有一个经度和纬度丰富的arrays。 我有两个双重variables与我的用户位置。 我想testing我的用户位置与我的arrays之间的距离,以查看哪个位置是最接近的。 我该怎么做呢? 这将获得2个位置之间的距离,但拼图理解我将如何对arrays的位置进行testing。 CLLocation *startLocation = [[CLLocation alloc] initWithLatitude:userlatitude longitude:userlongitude]; CLLocation *endLocation = [[CLLocation alloc] initWithLatitude:annotation.coordinate.latitude longitude:annotation.coordinate.longitude]; CLLocationDistance distance = [startLocation distanceFromLocation:endLocation];

iOS CoreLocation海拔高度

在iOS 4.0之前, CoreLocation正确报告高度,现在总是报告为0英尺。 -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation { NSString *tLatitude = [NSString stringWithFormat:@"%3.5f", newLocation.coordinate.latitude]; NSString *tLongitude = [NSString stringWithFormat:@"%3.5f", newLocation.coordinate.longitude]; /* the following returns 0 */ NSString *tAltitude = [NSString stringWithFormat:@"%i", newLocation.altitude]; /* theres more code, but it's not relevant, and this worked prior to iOS 4.0*/ [manager stopUpdatingLocation]; } 不在设备和模拟器上工作,是否有其他人遇到这个问题?

如何跟踪用户在后台的位置?

我正在寻找一个开源的应用程序或库来跟踪用户在后台的位置。 现在我正在尝试使用CLLocation和后台任务来做,但是对于我的情况来说,准确性还不够。 你能解释一下,“移动”,“跑步者”,“endmondo”等应用程序如何创build我的路线? 我应该使用加速度计还是/和指南针来创buildCLLocation背景点之间的路线? 一些代码: //location manager init self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.distanceFilter = kCLDistanceFilterNone; self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; self.locationManager.delegate = self; #pragma mark – CLLocationManager Delegate – (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { if ([self isInBackground]) { if (self.locationUpdatedInBackground) { bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler: ^{ [[UIApplication sharedApplication] endBackgroundTask:bgTask]; }]; self.locationUpdatedInBackground(newLocation); [self endBackgroundTask]; […]