iOS地图 很多坐标点 怎样显示所有坐标点 并使屏幕居中

    最近做地图遇到的问题记录一下 

(1) 地图 有很多坐标点是怎么找到中心点并使屏幕居中的代码。

 CLLocationCoordinate2D topLeftCoord;
            topLeftCoord.latitude = -90;
            topLeftCoord.longitude = 180;

            CLLocationCoordinate2D bottomRightCoord;
            bottomRightCoord.latitude = 90;
            bottomRightCoord.longitude = -180;

            for(VEDestionationMapModel *annotation in AnnosArr) {
                topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
                topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);
                bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS 高德地图 SDK 中,可以使用 `MAMapView` 对象进行地图显示和交互。该对象提供了一些方法可以实现坐标转换屏幕像素的功能。 以下是将地图上的经纬度坐标转换为屏幕像素的示例代码: ```objective-c // 初始化一个 MAMapView 对象 MAMapView *mapView = [[MAMapView alloc] initWithFrame:self.view.bounds]; // 创建一个 CLLocationCoordinate2D 类型的坐标 CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(39.908692, 116.397477); // 将经纬度坐标转换为屏幕像素 CGPoint point = [mapView convertCoordinate:coordinate toPointToView:self.view]; NSLog(@"Screen point: %@", NSStringFromCGPoint(point)); ``` 以上代码中,`convertCoordinate:toPointToView:` 方法可以将地图上的经纬度坐标转换为在当前视图中的屏幕像素坐标。其中 `toPointToView:` 参数表示需要转换到的视图对象,这里使用 `self.view` 表示当前视图。 除了将经纬度坐标转换为屏幕像素,还可以使用 `convertPoint:toCoordinateFromView:` 方法将屏幕像素坐标转换为地图上的经纬度坐标。示例代码如下: ```objective-c // 创建一个 CGPoint 类型的屏幕像素坐标 CGPoint point = CGPointMake(100, 200); // 将屏幕像素坐标转换为地图上的经纬度坐标 CLLocationCoordinate2D coordinate = [mapView convertPoint:point toCoordinateFromView:self.view]; NSLog(@"Coordinate: %f, %f", coordinate.latitude, coordinate.longitude); ``` 以上代码中,`convertPoint:toCoordinateFromView:` 方法可以将屏幕像素坐标转换为地图上的经纬度坐标。其中 `toCoordinateFromView:` 参数表示需要转换的视图对象,这里同样使用 `self.view` 表示当前视图。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值