我想在用户按下按钮时对用户当前位置进行注释,我尝试使用核心位置,但这是不兼容的。
这是一个例子:
-(IBAction)anotation:(sender){
CLLocationCoordinate2d *coor;
MKUserlocation *ul;
coor.latitude = **ul.location.latitude** //or something like that;
...
...
}
你能帮助我吗?
答案 0 :(得分:0)
尝试使用此操作zoomToCurrentLocation进行按钮单击。 getGotFix检查此回调设置的标志
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
这是IBAction代码(我确信SO上有重复项)
- (IBAction)zoomToCurrentLocation:(id)sender
{
MKCoordinateRegion region;
if ([utils getGotFix] == YES)
{
region.center = self.mapView.userLocation.coordinate;
MKCoordinateSpan span;
span.latitudeDelta = 2; // Change these values to change the zoom 1 degree = 69 miles
span.longitudeDelta = 2;
region.span = span;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(region.center, 2*METERS_PER_MILE, 2*METERS_PER_MILE);
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];
[mapView setRegion:adjustedRegion animated:YES];
}
else
{ // We dont yet have a user location fix so inform user
UIAlertView * timeoutAlert = [[UIAlertView alloc] initWithTitle:@"No location fix" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[timeoutAlert show];
}
}