試試這個動作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];
}
}
「我的核心位置嘗試設置,但它是不相容的。「這是什麼意思?你可以做到這一點,我做了很多次。你遇到了什麼確切的問題? –
如果你想顯示_default藍色dot_,只是做'mapView.showsUserLocation = YES;'(你不應該顯式地創建MKUserLocation註釋)。 – Anna
如何閱讀[位置感知指南(http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/Introduction/Introduction.html)? –