ios 百度地图指定区域_ios百度地图的使用(普通定位、反地理编码)

这篇博客介绍了如何在iOS中使用百度地图API进行普通定位和反地理编码。首先,文章讲解了如何设置权限、初始化CLLocationManager并获取定位信息。然后,展示了如何创建BMKMapView并设置属性,实现实时定位和地图显示。此外,还提供了一个UserLocationManager类来管理定位服务,包括开始、停止定位及处理定位更新的方法。
摘要由CSDN通过智能技术生成

iOS定位 - 普通定位(没有地图) - 反地理编码(得到具体位置),下面通过代码给大家详解,代码如下:

#import 使用到的头文件 要引入CoreLocation这个包

使用的代理名称

//1.使用定位服务

//设置app有访问定位服务的权限

//在使用应用期间 / 始终(app在后台)

//info.plist文件添加以下两条(或者其中一条):

//NSLocationWhenInUseUsageDescription 在使用应用期间

//NSLocationAlwaysUsageDescription 始终

//2.LocationManager 对象管理相关的定位服务

_manager = [[CLLocationManager alloc] init];

//manager判断: 手机是否开启定位 / app是否有访问定位的权限

//[CLLocationManager locationServicesEnabled]; //手机是否开启定位

//[CLLocationManager authorizationStatus]; //app访问定位的权限的状态

if (![CLLocationManager locationServicesEnabled] || [CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedWhenInUse) {

[_manager requestWhenInUseAuthorization]; //向用户请求访问定位服务的权限

}

_manager.delegate = self;

_manager.desiredAccuracy = kCLLocationAccuracyBest;

_manager.distanceFilter = 1.0f;

[_manager startUpdatingLocation];

//定位代理经纬度回调

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

[_manager stopUpdatingLocation];

CLGeocoder * geoCoder = [[CLGeocoder alloc] init];

[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *pla

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要获取百度地图可视区域范围的数据,你可以使用以下方法: 1. 获取当前地图的中心点坐标: ``` CLLocationCoordinate2D centerCoordinate = mapView.centerCoordinate; ``` 2. 获取当前地图的缩放级别: ``` float zoomLevel = mapView.zoomLevel; ``` 3. 计算出当前地图可视区域的四个顶点坐标: ``` BMKCoordinateRegion region = BMKCoordinateRegionMakeWithDistance(centerCoordinate, 1000 * pow(2, (21 - zoomLevel)), 1000 * pow(2, (21 - zoomLevel))); CLLocationCoordinate2D topLeftCoordinate = CLLocationCoordinate2DMake(centerCoordinate.latitude + region.span.latitudeDelta / 2.0, centerCoordinate.longitude - region.span.longitudeDelta / 2.0); CLLocationCoordinate2D bottomLeftCoordinate = CLLocationCoordinate2DMake(centerCoordinate.latitude - region.span.latitudeDelta / 2.0, centerCoordinate.longitude - region.span.longitudeDelta / 2.0); CLLocationCoordinate2D topRightCoordinate = CLLocationCoordinate2DMake(centerCoordinate.latitude + region.span.latitudeDelta / 2.0, centerCoordinate.longitude + region.span.longitudeDelta / 2.0); CLLocationCoordinate2D bottomRightCoordinate = CLLocationCoordinate2DMake(centerCoordinate.latitude - region.span.latitudeDelta / 2.0, centerCoordinate.longitude + region.span.longitudeDelta / 2.0); ``` 4. 将四个顶点坐标转换成百度地图的墨卡托坐标: ``` BMKMapPoint topLeftPoint = BMKMapPointForCoordinate(topLeftCoordinate); BMKMapPoint bottomLeftPoint = BMKMapPointForCoordinate(bottomLeftCoordinate); BMKMapPoint topRightPoint = BMKMapPointForCoordinate(topRightCoordinate); BMKMapPoint bottomRightPoint = BMKMapPointForCoordinate(bottomRightCoordinate); ``` 5. 计算出当前地图可视区域百度地图中的矩形区域: ``` BMKMapRect visibleRect = BMKMapRectMake(fmin(topLeftPoint.x, bottomLeftPoint.x), fmin(topLeftPoint.y, topRightPoint.y), fabs(topLeftPoint.x - topRightPoint.x), fabs(topLeftPoint.y - bottomLeftPoint.y)); ``` 6. 将矩形区域转换成经纬度坐标范围: ``` BMKCoordinateRegion visibleRegion = BMKCoordinateRegionForMapRect(visibleRect); CLLocationCoordinate2D visibleTopLeftCoordinate = visibleRegion.center; visibleTopLeftCoordinate.latitude += visibleRegion.span.latitudeDelta / 2.0; visibleTopLeftCoordinate.longitude -= visibleRegion.span.longitudeDelta / 2.0; CLLocationCoordinate2D visibleBottomRightCoordinate = visibleRegion.center; visibleBottomRightCoordinate.latitude -= visibleRegion.span.latitudeDelta / 2.0; visibleBottomRightCoordinate.longitude += visibleRegion.span.longitudeDelta / 2.0; ``` 最终,`visibleTopLeftCoordinate` 和 `visibleBottomRightCoordinate` 就是当前地图可视区域的经纬度坐标范围。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值