gpt4 book ai didi

ios - map 恢复到用户位置,不允许 'browse' iOS

转载 作者:行者123 更新时间:2023-11-29 03:55:59 25 4
gpt4 key购买 nike

应用程序的 map 屏幕显示用户的当前位置。我想允许用户“浏览” map (滚动并探索其他区域),并且我有一个按钮可以将用户返回到 map 上的点及其当前位置但是我发生的情况是应用程序不允许用户“浏览” map 并保留他们正在查看的 View ,而是直接跳回到用户当前的位置。

这是一些代码:

-(void) setupLocation {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
// locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// [self.mapView setCenterCoordinate:self.mapView.userLocation.coordinate animated:YES];

tempLat = newLocation.coordinate.latitude;
tempLon = newLocation.coordinate.longitude;
CLLocationCoordinate2D currentLocation = CLLocationCoordinate2DMake(tempLat, tempLon);
MKCoordinateRegion viewRegionLocation = MKCoordinateRegionMakeWithDistance(currentLocation, 100, 100);
[self.mapView setRegion:viewRegionLocation animated:YES];

locationNew = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];
locationOld = [[CLLocation alloc] initWithLatitude:oldLocation.coordinate.latitude longitude:oldLocation.coordinate.longitude];

}

我还有:

- (IBAction)stopUpdating:(id)sender {
[locationManager stopUpdatingLocation];
}

和:

- (IBAction)findMe:(id)sender {
[locationManager startUpdatingLocation];
}

关于为什么 map 不断跳回用户当前位置有什么想法吗?

非常感谢!

最佳答案

因为,在您的 - (void)locationManager: didUpdateToLocation: fromLocation: 方法中

您每次都将 map View 的区域设置为更新的位置。

删除这部分将解决您的问题。

  MKCoordinateRegion viewRegionLocation = MKCoordinateRegionMakeWithDistance(currentLocation, 100, 100);
[self.mapView setRegion:viewRegionLocation animated:YES];

编辑1:

在 viewDidLoad 方法中添加此行,

self.mapView.showsUserLocation = YES;

像这样更改“查找我”按钮的按下方法,

-(IBAction) findMeButtonPressed:(id)sender;{
MKCoordinateRegion viewRegionLocation = MKCoordinateRegionMakeWithDistance([self.locationManager location].coordinate, 100, 100);
[self.mapView setRegion:viewRegionLocation animated:YES];
}

关于ios - map 恢复到用户位置,不允许 'browse' iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16504983/

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