【问题标题】:How to set listener for current location pin on mapview?如何在地图视图上设置当前位置引脚的侦听器?
【发布时间】:2015-10-19 08:25:44
【问题描述】:

这是我到目前为止所做的:

_mapview.delegate = self;
_mapview.showsUserLocation = YES;
locationManager = [CLLocationManager new];
locationManager.delegate = self;
locationManager.distanceFilter = kCLLocationAccuracyKilometer;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
//iOS 8 API change
if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){
    [locationManager requestWhenInUseAuthorization];
}else{
    [locationManager startUpdatingLocation];
}
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
self.mapview.region = MKCoordinateRegionMakeWithDistance(coordinate, 1000, 1000);

我得到了这个观点:

我怎样才能有一个监听器,以便在用户点击当前位置图钉时进行捕捉。我试过了,calloutAccessoryControlTapped 不工作。

更新

我改成这样了:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    NSLog(@"MKAnnotationView");

    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"pin"];
    annView.canShowCallout = YES;
    UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    annView.rightCalloutAccessoryView=detailButton;
}

但稍后我需要获取当前位置地址。但标题不是它的地址。如何在图钉中显示当前位置地址,或者当用户单击图钉时,我会得到类似门牌号的地址。街道名称。城市名。状态:

static NSString *defaultPinID = @"pin";
MKPinAnnotationView *pinAnnotation = nil;
pinAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:view.annotation reuseIdentifier:defaultPinID];

self.address = view.annotation.title;
CLLocationCoordinate2D coor = [view.annotation coordinate];
_eventGeoLocation2 = [PFGeoPoint geoPointWithLatitude:coor.latitude longitude:coor.longitude];

【问题讨论】:

    标签: ios objective-c mkmapview


    【解决方案1】:

    您可以使用 MKPinAnnotationView 提供的默认详细信息披露按钮。这是代码,

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
    {
    
          MKPinAnnotationView *annView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"pin"];
          annView.canShowCallout = YES;
          UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
          annView.rightCalloutAccessoryView=detailButton;
    }
    

    一旦完成。您可以像这样使用现有的委托方法,

    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
    {
       //Here, the annotation tapped can be accessed using view.annotation
    
        NSLog(@"%@",view.annotation.title);
        NSLog(@"%@",view.annotation.subtitle);
       [self performSegueWithIdentifier:@"Your identifier" sender:view.annotation.title];
    }
    

    【讨论】:

    • 谢谢伙计。这工作正常,但我有一个问题。请看更新
    【解决方案2】:

    您是否尝试调用 GMSMapView 的委托方法?

    - (void)mapView:(GMSMapView *)mapView
        didTapInfoWindowOfMarker:(GMSMarker *)marker;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多