[英]core location proplem in simulator
我無法在iPhone模擬器中獲取當前位置。 我將自定義位置設置為埃及的經度和緯度,但未獲得當前位置。
- (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];
//Instantiate a location object.
locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
//Make this controller the delegate for the location manager.
[locationManager setDelegate:self];
//Set some parameters for the location object.
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
}
這是代表:
#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];
}
請任何人幫助我。
到底是什么問題? 無法獲得您應該擁有的userLocation或未將地圖區域移動到正確的地方?
如果是第一個,則主要是工具問題,而不是代碼問題:
如果您的位置在項目內的gpx文件中,則應該可以通過編輯“方案” /“選項” /“允許位置模擬” /並選擇默認位置來開始
並且您的項目中應該有一個DemoStart.gpx文件,如下所示:
<?xml version="1.0"?>
<gpx version="1.1" creator="Xcode">
<wpt lat="20.88072" lon="10.67429">
<name>Demo Starting Location</name>
</wpt>
</gpx>
(對不起,我太懶了,找不到埃及的確切坐標)。
您必須首先確保CLLocationManager將其位置更新為您的位置。 為此,請將視圖控制器設置為CLLocationManager的委托,然后保存該位置。 完成所有設置后,嘗試調用startUpdatingLocation
,並將showsUserLocation
設置為YES
。
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
// If it's a relatively recent event, turn off updates to save power
CLLocation* myLocation = [locations lastObject];
}
確保在iOS模擬器版本> = 5.1上對此進行測試
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.