-1

我想在用户按下按钮时对用户的当前位置进行注释,我尝试使用核心位置,但它不兼容。

这是一个例子:

-(IBAction)anotation:(sender){


    CLLocationCoordinate2d *coor;

    MKUserlocation *ul;

    coor.latitude = **ul.location.latitude** //or something like that;

    ...
    ...


}

你能帮助我吗?

4

1 回答 1

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];
}

}

于 2013-01-10T16:14:56.357 回答