位置与地图:定位获取设备的位置
2014-07-01 14:38
267 查看
首先添加Core Location框架,可以通过该框架中包含的类,获取设备的地理位置.
使用位置服务时,需要添加coreLocation.framework
#impart <CoreLocation/CoreLocation.h>
注意事项:
1.使用地图服务时,会消耗更多的设备电量.因此,在获取到设备的位置后,应该停止定位以节省点亮
2.将位置服务设置为全局变量
.h文件中
执行的代理方法
最终输出的结果是:
使用位置服务时,需要添加coreLocation.framework
#impart <CoreLocation/CoreLocation.h>
注意事项:
1.使用地图服务时,会消耗更多的设备电量.因此,在获取到设备的位置后,应该停止定位以节省点亮
2.将位置服务设置为全局变量
.h文件中
#import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> @interface AppDelegate : UIResponder <UIApplicationDelegate,CLLocationManagerDelegate> @property (strong, nonatomic) UIWindow *window; @property (strong,nonatomic) CLLocationManager *locationManager; @end.m文件中
//初始化位置服务 self.locationManager = [[CLLocationManager alloc]init]; //要求CLLocationManager对象返回全部的信息 [_locationManager setDistanceFilter:kCLDistanceFilterNone]; //设置定位经度 [_locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters]; //设置代理; _locationManager.delegate = self; //开始 实时定位 [_locationManager startUpdatingLocation];
执行的代理方法
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { CLLocation *newLocation = [locations objectAtIndex:0]; //获取新的经纬度 CLLocationCoordinate2D coordinate = newLocation.coordinate; NSLog(@"经度:%f,纬度:%f",coordinate.longitude,coordinate.latitude); [manager stopUpdatingLocation]; }通过模拟器调试自定义位置.来获取当前位置
最终输出的结果是:
相关文章推荐
- 位置与地图:定位获取设备的位置
- Android Map Api 使用和开发(2) 定位我的位置、地图弹出泡泡、通过经纬度获取地址
- Android Map Api 使用和开发(2) 定位我的位置、地图弹出泡泡、通过经纬度获取地址
- 微信小程序开发之真机测试 地图定位 map API 无法获取当前位置的问题
- 微信公众号、地图定位、获取地理位置
- IOS 地图定位,标记位置,获取经纬度,MKMapView的使用
- Android定位&地图&导航——基于百度地图移动获取位置和自动定位
- 微信小程序开发之真机测试 地图定位 map API 无法获取当前位置的问题
- Android Map Api 使用和开发(2) 定位我的位置、地图弹出泡泡、通过经纬度获取地址
- Android Map Api 使用和开发(2) 定位我的位置、地图弹出泡泡、通过经纬度获取地址
- 位置与地图(一)定位获取位置及位置编码-反编码
- Android Map Api 使用和开发(2) 定位我的位置、地图弹出泡泡、通过经纬度获取地址
- IOS——地图的使用、地图定位到当前位置(包括ios8获取位置)、地图标注的添加、地图放大缩小监听
- 转载 Android Map Api 使用和开发 定位我的位置、地图弹出泡泡、通过经纬度获取地址 浮动搜索框 ,通过地址名称获取经纬度和详细地址并定位
- Android Map Api 使用和开发(2) 定位我的位置、地图弹出泡泡、通过经纬度获取地址
- IOS 地图定位,标记位置,获取经纬度,MKMapView的使用
- IOS 地图定位,标记位置,获取经纬度,MKMapView的使用
- 【百度地图API·javascriptapi】地图定位、创建自定义图标、获取用户点击位置
- 微信小程序开发之真机测试 地图定位 map API 无法获取当前位置的问题
- Android Map Api 使用和开发(2) 定位我的位置、地图弹出泡泡、通过经纬度获取地址