#define LOCATION_DISTANCE 80.4672
- (void)viewDidLoad
{
[super viewDidLoad];
....some computation
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager startUpdatingLocation];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 360.0*NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[locationManager stopUpdatingLocation];
});
..........some more computation
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *obj = [locations lastObject];
if (obj.coordinate.latitude != 0 && obj.coordinate.longitude != 0)
{
CLLocationCoordinate2D currrentCoordinates ;
currrentCoordinates.latitude = obj.coordinate.latitude;
currrentCoordinates.longitude = obj.coordinate.longitude;
if(obj.horizontalAccuracy>0 && obj.horizontalAccuracy<100){
self.turnedOffLocationServices =YES;
[locationManager stopUpdatingLocation];
} .... more computation
[self setUpMap:currrentCoordinates];
}
- (void)setUpMap:(CLLocationCoordinate2D)currentCoordinates
{
MKCoordinateRegion extentsRegion = MKCoordinateRegionMakeWithDistance(currentCoordinates, LOCATION_DISTANCE, LOCATION_DISTANCE);
MKMapView *mvMap = [[MKMapView alloc] initWithFrame:CGRectMake(20, 594, 360, 347)];
mvMap.delegate = self;
[mvMap setRegion:extentsRegion animated:YES];
mvMap.mapType = MKMapTypeSatellite;
mvMap.autoresizingMask = UIViewAutoresizingNone;
//mvMap.showsUserLocation = YES;
NSLog(@"the current lat is %f", currentCoordinates.latitude);
NSLog(@"the current long val is %f", currentCoordinates.longitude);
[self.scrollView addSubview:mvMap];
ITMAnnotation *annotation = [[ITMAnnotation alloc] initWithCoordinate:currentCoordinates addressDictionary:nil];
annotation.title = @"Drag to Move Pin";
annotation.subtitle = [NSString stringWithFormat:@"%f %f", annotation.coordinate.latitude, annotation.coordinate.longitude];
NSLog(@"subtitle change at 314");
[mvMap addAnnotation:annotation];
self.tempMapView = mvMap;
}
因此,我有viewDidLoad創建位置管理器。我認爲它應該使用didUpdateLocations。我使用該座標調用setUpMap方法,並在我的ipad屏幕左下角看到一張地圖。 我的問題是:1)在無線/蜂窩模式下,我沒有得到準確的位置。它的方式。但我手動輸入座標(有文本字段,將採取這種座標),它的工作原理和顯示位置。 2)我在這個no-wifi/no cell模式中添加了4條記錄。我可以添加3個地圖顯示的罰款(但不同的位置方式離開我目前的位置)。但是在第四次(或稍後的一段時間),當我訪問地圖應該顯示的屏幕是白色的時候。這是否有道理?如果您需要更多信息,請詢問。謝謝..哦,所有這一切都在設備不模擬器。和它的iOS6。MKMapview沒有單元格/ wifi連接無法正確顯示在設備上
「no-wifi/no cell mode」是否指「飛機」模式?單元芯片是否關閉,或者您剛剛收到接收信號? – Craig
@Craig。我的意思是我關掉了我的設備上的wifi和cell。我將它們關閉以模擬沒有接收區域模式的情況。 – RookieAppler