[英]How to add Custom Map Pins to the Map View on the Apple Watch?
I am beginning to code for the Apple Watch and I am wondering how can I do this: 我开始为Apple Watch编写代码,我想知道如何做到这一点:
Thank you! 谢谢!
First you need to add a map view to your controller (for example InterceController.swift
) 首先,您需要向控制器添加地图视图(例如
InterceController.swift
)
Then, you can call these lines in your InterfaceController.swift
's awakeWithContext()
or willActivate()
然后,您可以在
InterfaceController.swift
的awakeWithContext()
或willActivate()
调用这些行。
let location = CLLocationCoordinate2D(
latitude: 51.530777,
longitude: -0.139364
)
let span = MKCoordinateSpan(
latitudeDelta: 0.005,
longitudeDelta: 0.005
)
let region = MKCoordinateRegion(center: location, span: span)
map.setRegion(region)
map.addAnnotation(location, withImageNamed: "bee.png", centerOffset: CGPoint(x: 0, y: 0))
The key is to call addAnnotation(location: CLLocationCoordinate2D, withImageNamed name: String!, centerOffset offset: CGPoint)
关键是调用
addAnnotation(location: CLLocationCoordinate2D, withImageNamed name: String!, centerOffset offset: CGPoint)
Equivalent Objective-C code: 等效的Objective-C代码:
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(51.530777, -0.139364);
MKCoordinateSpan span = MKCoordinateSpanMake(0.005, 0.005);
MKCoordinateRegion region = MKCoordinateRegionMake(location, span);
[self.map setRegion:region];
[self.map addAnnotation:location withImageNamed:@"bee.png" centerOffset:CGPointMake(0, 0)];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.