iOS 系统方法获取当前位置经纬度

1.首先要导入CoreLocation  这个框架

2.然后要用到这个类CLLocationManager

@property(nonatomic,strong)CLLocationManager* manger;

3.添加一下代理<CLLocationManagerDelegate>

4.下面是初始化一下本类和绑定代理(如果喜欢懒加载可以写成懒加载)

_manger= [[CLLocationManager alloc]init];

_manger.delegate=self;

//下面是开始定位

[_manger startUpdatingLocation];

5.然后定位成功后就会走下面代理方法

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

[_manger stopUpdatingLocation];

CLLocation*location = [locations lastObject];

CLLocationDegreeslatitude = location.coordinate.latitude;

CLLocationDegreeslongitude = location.coordinate.longitude;

NSLog(@"%f%f",latitude,longitude);

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容