缩放以适合当前位置和地图上的注释 [英] Zoom to fit current location and annotation on map

查看:85
本文介绍了缩放以适合当前位置和地图上的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不熟悉Swift(通常是iOS编程),正在尝试弄清楚如何缩小地图以适合地图上的2个点.

I am new to swift (iOS programming in general) and am trying to figure out how to zoom a map out to fit 2 points on the map.

当前我有

var zoomRect = MKMapRectNull;
var myLocationPointRect = MKMapRectMake(myLocation.longitude, myLocation.latitude, 0, 0)
var currentDestinationPointRect = MKMapRectMake(currentDestination.longitude, currentDestination.latitude, 0, 0)

zoomRect = myLocationPointRect;
zoomRect = MKMapRectUnion(zoomRect, currentDestinationPointRect);

什么都不做.

我是否必须以某种方式将zoomRect应用于地图?

Do I have to apply zoomRect to the map somehow?

推荐答案

MKMapRectUnion计算并返回一个新的rect,仅此而已.您需要告诉mapView将其可见区域设置为该新矩形:

MKMapRectUnion computes and returns a new rect, nothing more. You need to tell the mapView to set its visible area to that new rect:

myMapView.setVisibleMapRect(zoomRect, animated: true)

这篇关于缩放以适合当前位置和地图上的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆