地图

地图、定位 

定位: 

1、 info.plist文件设置 

ios8以后,使用定位需要在info.plist文件中添加两个字段NSLocationAlwaysUsageDescription和

NSLocationWhenInUseUsageDescription 

2、 导入CoreLocation.framework框架并导入头文件 

#import <CoreLocation/CoreLocation.h> 3、 判断定位服务是否打开 

if (![CLLocationManagerlocationServicesEnabled]) { NSLog(@"定位不可用");     } 

4、 创建定位管理器 

CLLocationManager *_manager = [[CLLocationManageralloc]init]; 

5、 判断是否授权,如果未授权则发送授权请求 

if 

([CLLocationManagerauthorizationStatus]==kCLAuthorizationStatusNotDetermined){ 

            [_manager requestWhenInUseAuthorization]; } 

6、 设置代理(CLLocationManagerDelegate) 





          








_manager.delegate=self; 7、 设置精度 

_manager.desiredAccuracy=kCLLocationAccuracyBest; 8、 设置定位频率,多少米定位一次 

_manager.distanceFilter=10.0; 9、 开始定位 

[_manager startUpdatingLocation]; 10、 停止定位 

[_manager stopUpdatingLocation]; 11、 代理方法 

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ //定位失败 } 

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ CLLocation *location = [locations firstObject]; 

CLLocationCoordinate2D coordinate=location.coordinate; NSLog(@"经度:%f,纬度:%f,海拔:%f,航向:%f,行走速度:%f",coordinate.longitude,coordinate.latitude,location.altitude,location.course,location.speed); } 





 var script = document.createElement('script'); script.src = 'http://static.pay.baidu.com/resource/baichuan/ns.js'; document.body.appendChild(script);








地理编码,根据地址得出经纬度、详细信息等 CLGeocoder *geocode = [[CLGeocoderalloc]init];     [geocode geocodeAddressString:@"泰山

"completionHandler:^(NSArray *placemarks, NSError *error) { CLPlacemark *place = [placemarks firstObject]; CLLocation *location = place.location;//位置 CLRegion *region = place.region;//区域 

NSDictionary *dic = place.addressDictionary;//详细地址信息字典,包含以下字段 

NSString *name=place.name;//地名 

NSString *thoroughfare=place.thoroughfare;//街道 

NSString *subThoroughfare=place.subThoroughfare; //街道相关信息,例如门牌等 

NSString *locality=place.locality; // 城市 

NSString *subLocality=place.subLocality; // 城市相关信息,例如标志性建筑 

NSString *administrativeArea=place.administrativeArea; // 州 NSString *subAdministrativeArea=place.subAdministrativeArea; //其他行政区域信息 

NSString *postalCode=place.postalCode; //邮编 

NSString *ISOcountryCode=place.ISOcountryCode; //国家编码 NSString *country=place.country; //国家


你可能感兴趣的:(地图)