我想在用户跟随的旋转的谷歌地图上显示自行车/汽车图像。怎么可能。我添加didUpdateToLocation
了更新用户位置的方法,并添加viewForAnnotation
了显示自行车当前位置的方法。但无法在用户关注的地图上显示自行车。
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocation *currentLocation = newLocation;
if(currentLocation != nil)
{
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);
MyAnnotation *annotation = [[MyAnnotation alloc] initWithCoordinates:location title:@"India" subTitle:@"Sarvopari Mall"];
[self.myMapView addAnnotation:annotation];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id <MKAnnotation>)annotation{
MKAnnotationView *result = nil;
if ([annotation isKindOfClass:[MyAnnotation class]] == NO)
{
return result;
}
if ([mapView isEqual:self.myMapView] == NO)
{
return result;
}
MyAnnotation *senderAnnotation = (MyAnnotation *)annotation;
NSString *pinReusableIdentifier =
[MyAnnotation
reusableIdentifierforPinColor:senderAnnotation.pinColor];
MKAnnotationView *annotationView = (MKAnnotationView *)
[mapView
dequeueReusableAnnotationViewWithIdentifier:
pinReusableIdentifier];
if (annotationView == nil){
annotationView =
[[MKAnnotationView alloc] initWithAnnotation:senderAnnotation
reuseIdentifier:pinReusableIdentifier];
annotationView.canShowCallout = YES;
}
UIImage *pinImage = [UIImage imageNamed:@"Bike.png"];
if (pinImage != nil){
annotationView.image = pinImage;
annotationView.canShowCallout = YES;
}
result = annotationView;
return result;
}