0

我一辈子都想不通这个。我已经能够在地图上获得注释并创建一个新的 Rect 来保存它们并将地图设置为该 rect 但我的问题显然是这些注释就在我的地图的边缘,我想添加一些额外的空间. 这是他们目前的样子

在此处输入图像描述

生成它的代码是

...
@IBOutlet var mapOutlet: WKInterfaceMap!
...

// setup a null MpRect
var zoomRect = MKMapRect.null;

// set lat and lon
let lat = data?["latitude"] as! Double
let lon = data?["longitude"] as! Double
let phoneLat = 32.801296
let phoneLon = -79.898318

// create coordinates
let myLocation = CLLocationCoordinate2D(latitude: lat, longitude: lon)
let phoneLocation = CLLocationCoordinate2D(latitude: phoneLat, longitude: phoneLon)

// setup location points
let myLocationPoint = MKMapPoint(myLocation)
let phoneLocationPoint = MKMapPoint(phoneLocation)

// setup MapRects
let myLocationRect = MKMapRect(x: myLocationPoint.x, y: myLocationPoint.y, width: 0.1, height: 0.1)
let phoneLocationRect = MKMapRect(x: phoneLocationPoint.x, y: phoneLocationPoint.y, width: 0.1, height: 0.1)

// setup MapRect union
zoomRect = myLocationRect;
zoomRect = zoomRect.union(phoneLocationRect);

mapOutlet.setVisibleMapRect(zoomRect)
mapOutlet.addAnnotation(myLocation, with: .red)
mapOutlet.addAnnotation(phoneLocation, with: .purple)
4

0 回答 0