は、私が現在を取得するためにCLLocationManager
デリゲート更新メソッドを使用前の位置を保存し、それらの間に補間した。もう少し努力しますが、トラッキングをよりスムーズにします。
#define zoomSpan MKCoordinateSpanMake(0.001f, 0.001f)
@property (strong, nonatomic) CLLocation *lastLocation;
@property (strong, nonatomic) MKMapView *mapView;
@property (strong, nonatomic) CLLocationManager *locationManager;
...
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *currentLocation = locations[locations.count - 1];
// Set to last location, for faster setting to correct position
[self.mapView setRegion:MKCoordinateRegionMake(self.lastLocation.coordinate, zoomSpan) animated:NO];
// Locations in-between coordinates for smooth tracking
CLLocationDegrees deltaLat = currentLocation.coordinate.latitude - self.lastLocation.coordinate.latitude;
CLLocationDegrees deltaLon = currentLocation.coordinate.longitude - self.lastLocation.coordinate.longitude;
NSArray *locationsArray = @[[[CLLocation alloc] initWithLatitude:(self.lastLocation.coordinate.latitude + deltaLat * 0.2)
longitude:(self.lastLocation.coordinate.longitude + deltaLon * 0.2)],
[[CLLocation alloc] initWithLatitude:(self.lastLocation.coordinate.latitude + deltaLat * 0.4)
longitude:(self.lastLocation.coordinate.longitude + deltaLon * 0.4)],
[[CLLocation alloc] initWithLatitude:(self.lastLocation.coordinate.latitude + deltaLat * 0.6)
longitude:(self.lastLocation.coordinate.longitude + deltaLon * 0.6)],
[[CLLocation alloc] initWithLatitude:(self.lastLocation.coordinate.latitude + deltaLat * 0.8)
longitude:(self.lastLocation.coordinate.longitude + deltaLon * 0.8)],
currentLocation];
float timer = 0;
for (CLLocation *nextLocation in locationsArray) {
[self performSelector:@selector(updateMapCenterLocation:) withObject:nextLocation afterDelay:timer];
timer += 0.2;
}
self.lastLocation = currentLocation;
}
- (void)updateMapCenterLocation:(CLLocation *)location
{
[self.mapView setRegion:MKCoordinateRegionMake(location.coordinate, zoomSpan) animated:YES];
}
は、あなたが(マップビューを保持し、通常はビューコントローラ)でこれを使用しているクラスはCLLocationManager
のデリゲートとCLLocationManagerDelegate
プロトコルを実装に設定されていることを確認してください:ここに私のコードです。
いくつかの追加コメント:
- このコードの動作は
MKUserTracking
に似ていますが、これは、カスタム設定したズームレベルをサポートしていません。トラッキングを開始するときにズームレベルをリセットするバグがあるように思われます。この回避策です。
zoomSpan
は現在固定されていますが、現在の地域のスパンをself.mapView.region.span
とすることもできます。
iOS 5では、この機能にトラッキングモードが追加されています。最後に! – d0n13