iPhone獲取消除誤差的位置信息

 偶然在一個demo中的找到了解決偏差的另外一種方法;<起初轉載了篇文章有兩種方法>

    

   1, MKMapView *_mapView;

     2,  _mapView.showsUserLocation = YES;//以大頭針的形式顯示用戶的所在位置;
     若[self.view addSubView:_mapview];地圖上面會自動標記所在的位置,但是我們這裏是想讓反向地址編碼獲取到正確的或者說是對應到地圖上面的沒有誤差的經緯度的位置信息,這裏我們可以註釋addSubView:即可。
   3,下面我們來獲取location信息;_mapView.userLocation.location。

.h

.m
//ViewDidLodad



我的demo裏面是讓一個按鈕點擊出發後開始找尋位置,

- (void)findMe:(id)sender{

    self.cllocationManager = [[[CLLocationManageralloc]init]autorelease];

    self.cllocationManager.delegate =self;//對應下面的委託方法121

    self.cllocationManager.desiredAccuracy =kCLLocationAccuracyBest;

    self.cllocationManager.distanceFilter =1.0f;

    [self.cllocationManagerstartUpdatingLocation];

}


//121委託方法,在.h裏面記得包含頭文件以及相關協議。

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {


    weidu.text = [NSStringstringWithFormat:@"%3.5f",newLocation.coordinate.latitude];

    jingdu.text = [NSStringstringWithFormat:@"%3.5f",newLocation.coordinate.longitude];


    //以上的經度,維度若要對應此newLocation映射到地圖上面會有偏移,大家所謂的火星座標;而有時候我們需要方向編碼查出響應的位置等信息,獲取正確的信息我們可以以來之前申明的

//_mapView.userLocation.location由字面意思及用戶的位置信息,包含經度維度,等等

CLGeocoder *geocoder = [[CLGeocoderalloc]init];

    [geocoder reverseGeocodeLocation_mapView.userLocation.locationcompletionHandler:^(NSArray*array,NSError *error) {

        if (array.count > 0) {

            CLPlacemark *placemark = [array objectAtIndex:0];

            NSString *country = placemark.ISOcountryCode;

            NSString *city = placemark.locality;


           NSLog(@"%@",placemark);

        }

    }];

//把placemark寫在委託方法裏面的意圖是讓

//    self.cllocationManager.distanceFilter = 1.0f; 距離變動有1m後回調此方法,然而此時我們又可以獲取到真實的location。



}


較最上面的第二種方法的好處自認爲一開始就可以獲取到的正確的location,並且可以設置過濾的精度,1m,或者0.1m。設置大點還可以節省電源。

//沒有修正的信息

2012-12-23 01:33:42.819 MapDemo[28470:707]中國四川省成都市青羊區小關廟街37,中國四川省成都市青羊區小關廟街37 @ <+30.66883500,+104.08376400> +/- 100.00m, region (identifier <+30.66883500,+104.08376400> radius 62.07) <+30.66883500,+104.08376400> radius 62.07m

//修正了的信息

2012-12-23 01:31:43.256 MapDemo[28449:707]中國四川省成都市青羊區北書院街,中國四川省成都市青羊區北書院街 @ <+30.66629472,+104.08632278> +/- 100.00m, region (identifier <+30.66684850,+104.08665200> radius 93.92) <+30.66684850,+104.08665200> radius 93.92m

發佈了13 篇原創文章 · 獲贊 1 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章