2013-01-22 29 views
0
#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連接無法正確顯示在設備上

+0

「no-wifi/no cell mode」是否指「飛機」模式?單元芯片是否關閉,或者您剛剛收到接收信號? – Craig

+0

@Craig。我的意思是我關掉了我的設備上的wifi和cell。我將它們關閉以模擬沒有接收區域模式的情況。 – RookieAppler

回答

1

單元和GPS位於同一芯片上,因此關閉單元也會關閉GPS。如果你只是想停止數據傳輸,但仍然需要GPS,那麼你可以在網絡設置下關閉移動數據。您仍然可以撥打電話,但您的設備無法下載任何內容(如果您也關閉了無線網絡)。

+0

那麼你可以告訴我,當用戶在沒有WiFi /沒有單元連接的地方使用具有MapView的應用程序時,地圖視圖會發生什麼?如果他在AirPlane上,那麼GPS是在兩個地方工作的? – RookieAppler

+0

GPS工作時沒有連接,因爲它是真正的GPS,它與衛星通話。但是如果關閉單元芯片(反過來在「飛機」模式下),GPS也會關閉。你仍然可以看到一些地圖數據,如果它已被緩存,但它不會再得到(顯然,沒有數據連接),但它不能解決你的位置。到那時,開發人員需要做些什麼。他們可以顯示錯誤,他們可以崩潰,他們可以等到GPS獲得信號。 – Craig

+0

GPS將在飛機上運行,​​但它被稱爲「飛機」模式,因爲大多數航空公司都希望您在飛行時關掉所有的東西。 – Craig

相關問題