iOS 地图
来源:互联网 发布:数据库工程师考试时间 编辑:程序博客网 时间:2024/05/22 08:22
1.在程序info中添加设置并导入Libraries(CoreLocation.framework)
NSLocationWhenInUseUsageDescription 打开定位服务提高服务质量(随便写)
导入Libraries(CoreLocation.framework)
2.主页面打开地图定位服务
#import <CoreLocation/CoreLocation.h>
<CLLocationManagerDelegate>
@property (nonatomic)CLLocationManager * locationManager;
//判断是否打开定位服务
if (![CLLocationManagerlocationServicesEnabled]) {
NSLog(@"Location Service Not Enabled");
return;
}
self.locationManager = [CLLocationManagernew];
if ([CLLocationManagerauthorizationStatus]==kCLAuthorizationStatusNotDetermined) {
[self.locationManagerrequestWhenInUseAuthorization];
}
self.locationManager.delegate =self;
[self.locationManagerstartUpdatingLocation];
#pragma mark - CLLocationManagerDelegate
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation * location = locations[0];
NSLog(@"%@", location);
[manager stopUpdatingLocation];
}
3.创建MapViewController
#import <MapKit/MapKit.h>
<MKMapViewDelegate>
@property (weak,nonatomic) IBOutletMKMapView *mapView;
@property (nonatomic)CLPlacemark * placemark;
@property (nonatomic)BOOL updateUserLocation;
if (self.userData.city.length<2)
{
return;
}
self.mapView.delegate =self;
CLGeocoder * geoCoder = [CLGeocodernew];
[geoCoder geocodeAddressString:self.userData.citycompletionHandler:^(NSArray *placemarks,NSError *error) {
self.placemark = placemarks[0];
MKPointAnnotation * ann = [MKPointAnnotationnew];
ann.coordinate =self.placemark.location.coordinate;
ann.title =self.userData.name;
ann.subtitle =self.userData.city;
[self.mapViewaddAnnotation:ann];
self.mapView.showsUserLocation =YES;
}];
#pragma mark -MKMapViewDelegate
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
if (!self.updateUserLocation) {
MKCoordinateSpan span =MKCoordinateSpanMake(fabs(userLocation.coordinate.latitude-self.placemark.location.coordinate.latitude)+1,fabs(userLocation.coordinate.longitude-self.placemark.location.coordinate.longitude)+1);
CLLocationCoordinate2D center =CLLocationCoordinate2DMake((userLocation.coordinate.latitude+self.placemark.location.coordinate.latitude)/2, (userLocation.coordinate.longitude+self.placemark.location.coordinate.longitude)/2);
MKCoordinateRegion region =MKCoordinateRegionMake(center, span);
[self.mapViewsetRegion:region animated:YES];
self.updateUserLocation =YES;
}
}
- IOS 地图
- ios地图
- iOS 地图
- iOS 地图
- iOS地图
- iOS - iOS 地图开发
- IOS Map地图
- iOS地图位置开发
- IOS地图定位
- iOS地图选址
- IOS地图定位
- iOS 地图位置开发
- iOS地图位置开发
- IOS 地图 应用
- IOS 地图定位概要
- iOS 地图位置处理
- ios 地图 自定义标注
- iOS地图位置开发
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- 创建GitHub技术博客
- linux下安装英语词典汇总
- iOS之OC随笔-Foudation框架下集合的相互转换
- 关于opencv的几个小总结
- iOS 地图
- Spring传播属性
- linux rmdir和rm的区别
- Windows Opencv-3.0 + Python-2.7.10 配置(numpy-1.8.1-64位)
- pandas库生成数据透视表
- Javascript基础(一)
- 用proxool配置数据库连接池步骤(自写管理类配置)
- 【最小生成树+二分】bzoj1196 公路修建问题
- 游戏编程大师技巧—windows程序的基本构造