因此,要使用唯一的 CLLocateManager,您可以创建一个类作为所有地图的委托。因此,不要这样做:
self.locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
执行以下操作:
self.locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = mySharedDelegate;
其中 mySharedDelegate 是您的类,其中包含所有 CLLocationManager 委托方法。
在第一次调用后,您只能获取 userLocation 的有效坐标
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
调用此方法是因为 GPS 已找到新位置,因此蓝点将移动到那里,并且 userLocation 将具有新坐标。
在您的 CLLocationManager 委托上使用以下方法在找到当前位置时记录它:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"---------- locationManager didUpdateToLocation");
location=newLocation.coordinate;
NSLog(@"Location after calibration, user location (%f, %f)", _mapView.userLocation.coordinate.latitude, _mapView.userLocation.coordinate.longitude);
}
你有这个想法吗?
干杯,
VFN