2009-10-30 125 views
1

每當我試圖返回經/緯座標爲我的當前位置,我的應用程序崩潰,沒有錯誤的解釋...返回Mapkit用戶位置座標

NSLog(@"%@", mapView.userLocation.location.coordinate); 

我在等待,直到手機找到位置以及...

回答

5

mapView.userLocation.location.coordinate是一個結構,而%@格式說明符需要一個對象。這將工作:

NSLog(@"%f, %f", mapView.userLocation.location.coordinate.latitude, 
       mapView.userLocation.location.coordinate.longitude); 
0

由於某種原因,這並不適用於我。它將我帶到座標(0.0000,0.0000)。下面是我的代碼,如果你有機會檢查出來。謝謝您的幫助!

[mapView setMapType:MKMapTypeStandard]; 
    [mapView setZoomEnabled:YES]; 
    [mapView setScrollEnabled:YES]; 
    mapView.showsUserLocation=TRUE; 

    MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 

    CLLocationCoordinate2D myCoord = {mapView.userLocation.location.coordinate.latitude,mapView.userLocation.location.coordinate.longitude}; 
    [mapView setCenterCoordinate:myCoord animated:YES]; 

    region.span.longitudeDelta = 0.01f; 
    region.span.latitudeDelta = 0.01f; 
    [mapView setRegion:region animated:YES]; 

    [mapView setDelegate:self];