打开地图需要有搜索周边的需求,但是
mapView:didUpdateUserLocation:updatingLocation:
方法调用了很多次,导致数据一直在刷新,不断搜索,及其容易引起崩溃,处理方法为,判断userlocation.location.horizontalAccuracy(水平精度)
- (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation {
if (updatingLocation) {
CLLocation *newLocation = userLocation.location;
//判断时间,定位时间是否正确
NSTimeInterval locationAge = [newLocation.timestamp timeIntervalSinceNow];
NSLog(@"%f",locationAge);
if (locationAge > 5.0) {
return;
}
//判断水平精度
if (!self.isLoacating) {
if (newLocation.horizontalAccuracy>0 && newLocation.horizontalAccuracy<150) {
NSLog(@"111222");
CLLocationCoordinate2D myCoorDinate = [newLocation coordinate];
self.mapView.centerCoordinate = myCoorDinate;
self.isLoacating = YES;
[self searchNearBy];
}
}
}
}
参考链接:
iOS高德地图开发【一】
网友评论