在我应用程序中,我有一个纬度和经度数组,其中有5-6个位置,我想缩短与当前位置的距离并将其显示在地图视图上。例如:我有3个位置A、B和C,因此如果位置C靠近我的当前位置,则我想根据当前位置缩短它们的长度,然后首先在地图上显示C位置,然后计算位置A和B,并使用位置C表示哪个位置离地点C近如果B靠近地点C,则在地图上显示B位置,最后显示位置A
我们如何做到这一点?
发布于 2012-09-04 19:22:15
查看两个位置之间的距离
CLLocation *locA = [[CLLocation alloc] initWithLatitude:latA longitude:longA];
CLLocation *locB = [[CLLocation alloc] initWithLatitude:latB longitude:longB];
CLLocation *locC = [[CLLocation alloc] initWithLatitude:latC longitude:longC];
CLLocation *yourLoc = [[CLLocation alloc] initWithLatitude:yourLat longitude:yourLong];然后获取地点与您所在位置之间的距离
CLLocationDistance distance = [locA distanceFromLocation:yourLoc];
CLLocationDistance distance2 = [locB distanceFromLocation:yourLoc];
CLLocationDistance distance3 = [locC distanceFromLocation:yourLoc];最后比较距离。
https://stackoverflow.com/questions/12262297
复制相似问题