简体   繁体   English

自定义注释引脚会干扰Iphone上的mkmapview的showuserlocation

[英]Custom Annotation pin interfere with mkmapview's showuserlocation on Iphone

Normally if you have showuserlocation enabled, and going to mapview, there will blue point zoom in dynamically to the user's current location. 通常,如果您启用了showuserlocation并转到mapview,则会动态地将蓝点放大到用户的当前位置。 However, if a custom annotation pin is created for different color purpose then the showuserlocation ability will disappear. 但是,如果为不同的颜色目的创建自定义注释引脚,则showuserlocation能力将消失。 The code below newAnnotation is culprit. newAnnotation下面的代码是罪魁祸首。 How do you have both custom pin and also showuserlocation ability not interfered. 你如何同时拥有自定义引脚和showuserlocation能力不受干扰。

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
 {

 if ([[annotation title] isEqualToString:@"Destination"])
  {
MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"greenpin"];
newAnnotation.pinColor = MKPinAnnotationColorGreen;
newAnnotation.animatesDrop = YES;
newAnnotation.canShowCallout = YES;
return newAnnotation;
 }

}

Try this 尝试这个

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    // if it's the user location, just return nil.
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

    if ([[annotation title] isEqualToString:@"Destination"])
    {
        MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc]  initWithAnnotation:annotation reuseIdentifier:@"greenpin"];
        newAnnotation.pinColor = MKPinAnnotationColorGreen;
        newAnnotation.animatesDrop = YES;
        newAnnotation.canShowCallout = YES;
        return newAnnotation;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM