1、三个属性
BMKPointAnnotation *customAnnotation;
BMKAnnotationView *newAnnotationView;
float direction;
2、didUpdateUserHeading方法中
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{
[_myMap updateLocationData:userLocation];
//NSLog(@"heading is %@",userLocation.heading);
if(nil == userLocation || nil == userLocation.heading
|| userLocation.heading.headingAccuracy < 0) {
return;
}
CLLocationDirection theHeading = userLocation.heading.magneticHeading;
direction = theHeading;
if(nil != newAnnotationView) {
if (direction > 180)
{
direction = 360 - direction ;
}
else
{
direction = 0 - direction ;
}
newAnnotationView.image = [UIImage imageNamed:@"my_car"];
newAnnotationView.image = [newAnnotationView.image imageRotatedByDegrees: - direction];
}
}
3、viewForAnnotation
#pragma mark -显示大头针
- (BMKAnnotationView *)mapView:(BMKMapView *)view viewForAnnotation:(id <BMKAnnotation>)annotation
{
if ([annotation isKindOfClass:[RouteAnnotation class]]) {
return [(RouteAnnotation*)annotation getRouteAnnotationView:view];
}
//此部分为自己添加的部分
if (annotation == customAnnotation) {
if (newAnnotationView == nil) {
newAnnotationView = [[BMKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
}
return newAnnotationView;
}
return nil;
}
4、添加自定义的大头针
- (void)createOverlay{
CLLocationCoordinate2D annotationCoor = {self.latitudeF, self.longitudeF};
if (customAnnotation == nil) {
customAnnotation = [[BMKPointAnnotation alloc] init];
}
customAnnotation.coordinate = annotationCoor;
[_myMap addAnnotation:customAnnotation];
}
didUpdateBMKUserLocation:(BMKUserLocation *)userLocation实时调用