第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何獲取用戶(hù)當(dāng)前的城市名稱(chēng)?

如何獲取用戶(hù)當(dāng)前的城市名稱(chēng)?

您如何檢索用戶(hù)的當(dāng)前城市名稱(chēng)?
查看完整描述

3 回答

?
弒天下

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊

您需要做的是設(shè)置一個(gè)CLLocationManager可以找到您當(dāng)前坐標(biāo)的坐標(biāo)。使用當(dāng)前坐標(biāo),您需要使用它MKReverseGeoCoder來(lái)找到您的位置。


- (void)viewDidLoad 

{  

    // this creates the CCLocationManager that will find your current location

    CLLocationManager *locationManager = [[[CLLocationManager alloc] init] autorelease];

    locationManager.delegate = self;

    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;

    [locationManager startUpdatingLocation];

}


// this delegate is called when the app successfully finds your current location

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

{

    // this creates a MKReverseGeocoder to find a placemark using the found coordinates

    MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];

    geoCoder.delegate = self;

    [geoCoder start];

}


// this delegate method is called if an error occurs in locating your current location

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 

{

 NSLog(@"locationManager:%@ didFailWithError:%@", manager, error);

}


// this delegate is called when the reverseGeocoder finds a placemark

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark

{

    MKPlacemark * myPlacemark = placemark;

    // with the placemark you can now retrieve the city name

    NSString *city = [myPlacemark.addressDictionary objectForKey:(NSString*) kABPersonAddressCityKey];

}


// this delegate is called when the reversegeocoder fails to find a placemark

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error

{

    NSLog(@"reverseGeocoder:%@ didFailWithError:%@", geocoder, error);

}


查看完整回答
反對(duì) 回復(fù) 2019-11-05
?
湖上湖

TA貢獻(xiàn)2003條經(jīng)驗(yàn) 獲得超2個(gè)贊

從iOS 5開(kāi)始MKReverseGeoCoder不推薦使用!


因此,您想使用CLGeocoderwith CLLocationManager,非常簡(jiǎn)單,并且可以使用block。


例:


- (void)locationManager:(CLLocationManager *)manager

    didUpdateToLocation:(CLLocation *)newLocation

           fromLocation:(CLLocation *)oldLocation

{

   [self.locationManager stopUpdatingLocation];


   CLGeocoder * geoCoder = [[CLGeocoder alloc] init];

    [geoCoder reverseGeocodeLocation:newLocation

                   completionHandler:^(NSArray *placemarks, NSError *error) {

                       for (CLPlacemark *placemark in placemarks) {

                           .... = [placemark locality];

                       }

                   }];

}

編輯:除了for in循環(huán),您還可以執(zhí)行以下操作:


NSString *locString = placemarks.count ? [placemarks.firstObject locality] : @"Not Found";


查看完整回答
反對(duì) 回復(fù) 2019-11-05
  • 3 回答
  • 0 關(guān)注
  • 968 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)