2012-10-22 29 views
1

我試圖表明我的當前位置在Mapkit這是代碼CoreLocation,MapKit錯誤

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    //Make this controller the delegate for the map view. 
    self.MapView.delegate = self;  

    // Ensure that you can view your own location in the map view. 
    [self.MapView setShowsUserLocation:YES]; 
    locationManager = [[CLLocationManager alloc] init]; 
    [locationManager setDelegate:self]; 
    [locationManager setDistanceFilter:kCLDistanceFilterNone]; 
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; 
} 

,我寫了這個委託的Mapkit

#pragma mark - MKMapViewDelegate methods. 
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views {  
    MKCoordinateRegion region; 
    region = MKCoordinateRegionMakeWithDistance(locationManager.location.coordinate,2000,2000); 


    [mv setRegion:region animated:YES]; 
} 

,但我得到錯誤的位置蔭在埃及和這給美國Iam在美國 任何一個可以幫我ME?

回答

1

以防萬一:如果您使用模擬器,該位置將不會是您的真實位置。您必須在模擬器中設置您的位置: 調試 - >位置 - >自定義位置(或其他任何地方)

+0

如何將它設置到埃及? – user1752619

+0

你必須輸入你的位置的經度和緯度。所以,啓動模擬器,去調試 - >位置 - >自定義位置,並將其設置爲30.2,31.5 – Nicholas

+0

BIG謝謝尼古拉斯:) 我做這個,它顯示我在地圖上埃及但不是當前位置 – user1752619

1

首先。

你沒有使用

[locationManager startUpdatingLocation]; 

你發起位置管理器變量後,請加入這一行。如果您在模擬器中看到這個位置,請讓我知道。

如果是:您的模擬器模擬用戶首選項給出的位置。進入模擬器窗口,在那裏你可以選擇按照你的選擇顯示自定義位置。默認情況下它被選爲美國。

希望它能解決您的問題。

+0

我無法找到用戶偏好? 我可以在哪裏罰款? – user1752619

+0

當您運行項目時,在調試窗口頂部有一個箭頭鍵類型按鈕,您也可以將它用於自定義位置。 iPhone模擬器中也有選項,調試>位置選項。 – iCreative