Reputation: 3017
I am beginning to code for the Apple Watch and I am wondering how can I do this:
Thank you!
Upvotes: 2
Views: 1550
Reputation: 6931
First you need to add a map view to your controller (for example InterceController.swift
)
Then, you can call these lines in your InterfaceController.swift
's awakeWithContext()
or 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)
Equivalent Objective-C code:
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)];
Upvotes: 5