mapkit とコアロケーションを使用した地図で、ユーザーの移動経路に車/自転車を向けたい。どうすればそれが可能になりますか? グーグルマップの方角を調べることで可能でしょうか?はいの場合、その数式は何ですか?
CLLocation のコース プロパティを試しましたが、無効な方向を示す -1 値が常に与えられます。
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *AnnotationViewID = @"annotationViewID";
annotationView = (MKAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.image = [UIImage imageNamed:@"Bike.png"];
annotationView.transform = CGAffineTransformMakeRotation(45);
return annotationView;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
if (newLocation.horizontalAccuracy < 0)
return;
if (!newLocation)
return;
currentLocation = newLocation;
previousLocation = oldLocation;
if(currentLocation != nil)
{
if (myAnnotation)
{
[self.myMapView removeAnnotation:myAnnotation];
}
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(currentLocation.coordinate.latitude, currentLocation.coordinate.longitude);
myAnnotation = [[MyAnnotation alloc] initWithCoordinates:location title:@"Current Location" subTitle:nil];
[self.myMapView addAnnotation:myAnnotation];
}
}