xcode6以後,新建工程定位需要進行偏好設定:
在info.plist檔案新增一下預設字段,可設為string型別,也可設為boolean型別(需要設指為yes)
nslocationwheninuseusagedescription //當使用時才回定位,允許在前台獲取gps的描述
nslocationalwaysusagedescription //總是使用定位,允許在前、後台獲取gps的描述原始碼如下:
真機執行:#import @inte***ce viewcontroller ()
@end
@implementation viewcontroller
- (void)viewdidload
//設定定位管理者**
_locationmanager.delegate = self;
//如果當前版本為8.0及以上,就總是定位
if ([[[uidevice currentdevice] systemversion] floatvalue] >= 8.0)
[_locationmanager setdesiredaccuracy:kcllocationaccuracybest]; //設定最好為最佳
[_locationmanager setdistancefilter:50.0f]; //設定定位距離為50公尺
//開啟定位
[_locationmanager startupdatinglocation];
}#pragma mark - 定位管理者**方法
- (void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray*)locations
]];
[self presentviewcontroller:ac animated:yes completion:nil];
}];//停止定位
[_locationmanager stopupdatinglocation];
}- (void)locationmanager:(cllocationmanager *)manager didfailwitherror:(nserror *)error
補充知識:
// placemark.addressdictionary
nslog(@"%@", placemark.addressdictionary[@"city"]); //城市
nslog(@"%@", placemark.addressdictionary[@"country"]); //國家
nslog(@"%@", placemark.addressdictionary[@"countrycode"]); //國家代號
nslog(@"%@", [(nsarray *)(placemark.addressdictionary[@"formattedaddresslines"]) firstobject]); //全名,從國家到門牌號,按國家格式排列輸出
nslog(@"%@", placemark.addressdictionary[@"name"]); //全名,從國家到門牌號
nslog(@"%@", placemark.addressdictionary[@"state"]); //省
nslog(@"%@", placemark.addressdictionary[@"street"]); //thoroughfare & subthoroughfare
nslog(@"%@", placemark.addressdictionary[@"sublocality"]); //區縣
nslog(@"%@", placemark.addressdictionary[@"subthoroughfare"]); //門牌
nslog(@"%@", placemark.addressdictionary[@"thoroughfare"]); //路
IOS 城市定位詳解及簡單例項
ios 城市定位 前言 獲取經緯度並且轉換成城市 ios8定位失敗解決 獲取中文城市 1 建立簡單的專案hdyyqcfie,匯入coreloation.framework 2 在info.plist中加上nslocationalwaysusagedescription值為alwayslocation...
IOS 定位服務
ios中的core location提供了定位功能,能定位裝置的當前座標,同時能得到裝置移動資訊。因為對定位裝置的輪詢是很耗電的,所以最好只在非常必要的前提下啟動。其中,最重要的類是cllocationmanager,定位管理。其定位有3種方式 1,gps,最精確的定位方式,貌似iphone1是不支...
iOS 定位 基礎
原文 ios中的core location提供了定位功能,能定位裝置的當前座標,同時能得到裝置移動資訊。因為對定位裝置的輪詢是很耗電的,所以最好只在非常必要的前提下啟動。其中,最重要的類是cllocationmanager,定位管理。其定位有3種方式 1,gps,最精確的定位方式,貌似iphone1...