這是我迄今所做的:如何在mapview上設置當前位置的監聽器?
_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];
謝謝隊友。這工作正常,但我有一個問題。請看看更新 – Bernard