ios 定位工具类
来源:互联网 发布:潍坊行知学校邮编 编辑:程序博客网 时间:2024/06/01 10:21
//
// LocationTool.m
// QduniversityJobhelper
//
// Created by niuxinghua on 14-12-21.
// Copyright (c) 2014年 niuxinghua. All rights reserved.
//
#import "LocationTool.h"
@implementation LocationTool
-(NSString*)locate{
if([CLLocationManagerlocationServicesEnabled]) {
_manager = [[CLLocationManageralloc] init];
self.manager.delegate =self;
}else {
//提示用户无法进行定位操作
NSLog(@"无法定位。。。");
}
// 开始定位
[_managerstartUpdatingLocation];
CLGeocoder *geocoder = [[CLGeocoderalloc] init];
//根据经纬度反向地理编译出地址信息
[geocoder reverseGeocodeLocation:_locationcompletionHandler:^(NSArray *array,NSError *error)
{
if (array.count >0)
{
CLPlacemark *placemark = [arrayobjectAtIndex:0];
//获取城市
_city = placemark.locality;
if (!_city) {
//四大直辖市的城市信息无法通过locality获得,只能通过获取省份的方法来获得(如果city为空,则可知为直辖市)
_city = placemark.administrativeArea;
}
NSLog(@"city = %@",_city);
}
else if (error ==nil && [array count] == 0)
{
NSLog(@"No results were returned.");
}
else if (error !=nil)
{
NSLog(@"An error occurred = %@", error);
}
}];
//系统会一直更新数据,直到选择停止更新,因为我们只需要获得一次经纬度即可,所以获取之后就停止更新
[_managerstopUpdatingLocation];
return _city;
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
//此处locations存储了持续更新的位置坐标值,取最后一个值为最新位置,如果不想让其持续更新位置,则在此方法中获取到一个值之后让locationManager stopUpdatingLocation
CLLocation *currentLocation = [locationslastObject];
CLLocationCoordinate2D coor = currentLocation.coordinate;
self.latitude = coor.latitude;
self.longitude = coor.longitude;
//[self.locationManager stopUpdatingLocation];
}
@end
- ios 定位工具类
- IOS 元素定位工具
- iOS定位坐标转换工具
- 百度定位工具类
- 定位相关工具类
- java工具类快速定位
- iOS开发——基于corelocation位置定位——工具类
- IOS定位
- IOS定位
- IOS 定位
- iOS定位
- ios 定位
- IOS 定位
- iOS 定位
- ios定位
- iOS定位
- iOS 定位
- ios 定位
- 动漫发展前线
- 笔记:深入理解JVM 第3章 垃圾回收器与内存分配策略
- 程序员思维释放(一):打破常态
- 第17周项目6--学生成绩统计(1.2.3.)
- Android -- BroadCastReceiver的简单使用
- ios 定位工具类
- Oracle的pipelined函数实现高性能大数据处理
- c++模板元编程学习笔记(二)——量纲框架
- 有时会忽略的造成Time Limit Exceeded错误的原因
- 2015年嵌入式软件岗位笔试题目总结
- C++学习之域运算符 ::
- AFNetworking之AFJSONRequestSerializer使用
- 设计模式之——结构型模式
- 摘自一篇好文章