iOS8 根據(jù)經(jīng)緯度顯示地名
來源:易賢網(wǎng) 閱讀:1342 次 日期:2015-01-22 09:41:49
溫馨提示:易賢網(wǎng)小編為您整理了“iOS8 根據(jù)經(jīng)緯度顯示地名”,方便廣大網(wǎng)友查閱!

我們很多時(shí)候做項(xiàng)目的時(shí)候都選用通過手機(jī)獲取定位,然后傳數(shù)據(jù)給后臺(tái),這是iOS8根據(jù)經(jīng)緯度顯示地名的demo

//1.導(dǎo)入框架

//

// NearByViewController.m

// nearDemo

//

// Created by apple on 14/12/5.

// Copyright (c) 2014年 youdianshang. All rights reserved.

//

#import

#import

@interface NearByViewController ()

{

NSUserDefaults *defaluts;

NSString * jingduStr;

NSString *weiduStr;

NSString *LocationAddress;

}

@property(nonatomic,retain)CLLocationManager *locationManager;

@property(strong,nonatomic)UILabel *positionLabel;

/*

經(jīng)緯度相關(guān)設(shè)置

*/

-(void)getLocationAll

{

self.locationManager = [[CLLocationManageralloc]init];

_locationManager.delegate =self;

_locationManager.desiredAccuracy =kCLLocationAccuracyBest;

_locationManager.distanceFilter =10;

[_locationManagerrequestAlwaysAuthorization];//添加這句

[_locationManagerstartUpdatingLocation];

}

/*

//通過經(jīng)緯度得到當(dāng)前地理位置

-(void)change{

defaluts=[NSUserDefaultsstandardUserDefaults];

CLLocationCoordinate2D coordinate;

coordinate.latitude = [[NSStringstringWithFormat:@"];

coordinate.longitude = [[NSStringstringWithFormat:@"];

CLLocation *newLocation=[[CLLocationalloc]initWithLatitude:coordinate.latitudelongitude: coordinate.longitude];

CLGeocoder *geocoder=[[CLGeocoderalloc] init];

[geocoder reverseGeocodeLocation:newLocationcompletionHandler:^(NSArray* placemarks,NSError* error)

{

MKPlacemark*placemark = [placemarks objectAtIndex:0];

LocationAddress = [NSStringstringWithFormat:@"@", placemark.locality, placemark.subLocality,placemark.thoroughfare, placemark.subThoroughfare];

[defaluts setObject:LocationAddress forKey:@"address"];

NSLog(@"終極目標(biāo):1:%@2:%@3:%@4:%@", placemark.locality, placemark.subLocality,placemark.thoroughfare,placemark.subThoroughfare);

}];

#pragma mark--實(shí)現(xiàn)CLLocationManagerDelegate的代理方法,獲取地理位置(鑌)===========================================================================

//(1)獲取到位置數(shù)據(jù),返回的是一個(gè)CLLocation的數(shù)組,一般使用其中的一個(gè)

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

{

CLLocation *currLocation = [locations lastObject];

NSLog(@"經(jīng)度=%f緯度=%f高度=%f", currLocation.coordinate.latitude, currLocation.coordinate.longitude, currLocation.altitude);

jingduStr =[NSStringstringWithFormat:@"%f", currLocation.coordinate.latitude];

weiduStr =[NSStringstringWithFormat:@"%f", currLocation.coordinate.longitude];

NSLog(@"jijijijijij:%@",jingduStr);

[self change];

}

//(2)獲取用戶位置數(shù)據(jù)失敗的回調(diào)方法,在此通知用戶

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

{

if ([error code] ==kCLErrorDenied)

{

//訪問被拒絕

}

if ([errorcode] == kCLErrorLocationUnknown) {

//無法獲取位置信息

}

}

更多信息請(qǐng)查看IT技術(shù)專欄

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:iOS8 根據(jù)經(jīng)緯度顯示地名
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國考·省考課程試聽報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)