2013-01-10 80 views
-1

基於用戶位置的註釋我想要做用戶的當前位置的註釋,當他按下一個按鈕,我試圖與核心的位置,但它是未對應。請在IBAction爲

這是一個例子:

-(IBAction)anotation:(sender){ 


    CLLocationCoordinate2d *coor; 

    MKUserlocation *ul; 

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

    ... 
    ... 


} 

你能幫助我嗎?

+0

「我的核心位置嘗試設置,但它是不相容的。「這是什麼意思?你可以做到這一點,我做了很多次。你遇到了什麼確切的問題? –

+2

如果你想顯示_default藍色dot_,只是做'mapView.showsUserLocation = YES;'(你不應該顯式地創建MKUserLocation註釋)。 – Anna

+0

如何閱讀[位置感知指南(http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/Introduction/Introduction.html)? –

回答

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

}