これは私がこれまでに行ったことです:
_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];
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];
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加