gpt4 book ai didi

ios - 在ios中找到我的位置和一个点之间的距离

转载 作者:行者123 更新时间:2023-11-29 10:25:33 24 4
gpt4 key购买 nike

我正在使用一种方法来获取我的位置:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {


CLLocation *currentLocation = newLocation;

NSLog(@"%@", currentLocation);}


//new method to find the distance
-(void) zoomToNearestSpot: (NSArray *) spot location: (CLLocation *)myLocation
{
myLocation = currentLocation;

spot = chSpot;

for (int i=0; i< spot.count; i++)
{
ChargingSpots *mySpot = [spot objectAtIndex:i];

CLLocation *thePoint = [[CLLocation alloc]initWithLatitude:[mySpot.LocationLat doubleValue] longitude:[mySpot.LocationLong doubleValue]];

CLLocationDistance dist = [myLocation distanceFromLocation:thePoint];

NSLog(@"%f", dist);


you get here **distance** in meter so in assumption **20 miles = 32187 meter**

放条件如

if(distance <= 32187)
{
// under 20 miles you can add the zoom level
}
else
{
// out of 20 miles
}



}
}

首先,我需要根据 map 上的编号缩小显示 map 上的所有地点,然后找到最近的地点并在其上放大相机。

最佳答案

你有更多的两个坐标

1) current (user Location)
2) another coordinate ..

在这里distanceFromLocation:方法用于获取两个位置之间的距离。

CLLocationDistance distance = [currentLOcation distanceFromLocation:anotherLocation];

例如你需要添加以下几行

-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{

CLLocation *currentLocation = newLocation;

for (int i=0; i<chSpot.count; i++)
{

ChargingSpots *spot = [chSpot objectAtIndex:i];
NSString *locLat = spot.LocationLat;
NSString *locLong = spot.LocationLong;

CLLocation *LocationAtual = [[CLLocation alloc] initWithLatitude: locLat longitude: locLong];

CLLocationDistance distanceBetween = [currentLocation
distanceFromLocation: LocationAtual];

NSString *tripString = [[NSString alloc]
initWithFormat:@"%f",
distanceBetween];

NSLog(@"DIST: %f", tripString);
}

}

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

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