How do you get a map view in watchOS 2.0?

So MKMapViewDelegate is no longer supported in watchOS 2. How, then, do I retrieve a map view to show in my watch app? Currently "map" is still supported as a drag-and-drop object in watchkit IB, but if you can't have a MKMapViewDelegate, nor import MapKit it seems like this is a useless object. Do you have to use WCSession to manage this? If so, how?


I've been scouring around and have found nothing so far on how to show a live (updating) map view on the watch as of version 2.


Thanks for the help!

Replies

MKMapViewDelegate works with instances of MKMapView, which only work on iOS so it was never supported on watchOS.


The WKInterfaceMap object in watchOS is just for static maps, so for example showing the position of a POI on a map, which can be useful. You can set the area displayed and add up to 5 annotations. I tend to use one annotation for a static blue dot to indicate the current position, which is not ideal (a moving map would be much better), but at least gives an idea of where you are.


It may be possible to approximate a live map by using Core Location to request location updates and then periodically updating the map area and blue dot position accordingly, but I haven't tried it. It would be interesting to see if it animates smoothly in real-time, which was unlikely in watchOS1, but may be possible now that the extension runs on the watch.

Hi, cfc, I was in fact using MKMapViewDelegate in my older code (watch OS 1) and it worked fine. I'd just request an updated map periodically and display it in the WKInterfaceMap object. The issue now is the MKMapViewDelegate is disallowed by watchOS 2: it throws an error if I leave it in. Basically the old code ran on the phone (so MKMap was fine) and transmitted images to the watch. The new code runs on the watch only, so doesn't (directly) support a map. I just need to understand how one now requests and updates a WKInterfaceMap object. Does anyone know how to do this?


I see new things like MapSequenceViewStructure, but there is very little documentation. I'm hoping someone (perhaps from Apple) has knowledge of how to display maps in watchOS 2. Thanks!

So were you using a MKMapView in your extension running on the phone and taking snapshots of that when the GPS position changed and sending the images to the watch, where they were displayed in an image/button/group control?


Do you need functionality that MKMapView offers but WKInterfaceMap doesn't, such as overlays? If not then it is much simpler to just use a WKInterfaceMap and just set the region you want to show as I explained before.


If you need overlays or other functionality not available in WKInterfaceMap then you should be able to use MKMapView in the iPhone app (rather than the extension) and send the images using WatchConnectivity as you suggest. The WWDC video is probably a good place to start:


https://developer.apple.com/videos/wwdc/2015/?id=713


There is also a sample project that includes an example of how to use it:


https://developer.apple.com/library/prerelease/watchos/samplecode/Lister/Introduction/Intro.html


Hope this helps.

Hey thanks for the response. I'm not exactly sure how it worked previously, but in watchOS 1 I just used this line and it magically worked:

self.mapView.setRegion(region)

(after all the setup of course).


I'd update the location when I was given a new coordinate, and that line would produce my map view. The trouble with watchOS 2 is that I am getting a spinning "wheel" (or whatever that thing is) and the map view never appears. I don't need anything fancy: I just want to show the user where he/she is currently on the map. I'm not sure why I don't get an error, but I get no map updates. On my phone version, the mapping works just fine, and like I said if I use my code in XCode (not beta) it works fine with watchOS 1 simulator.


If I'm understnding you correctly, using setRegion should still work in watchOS 2? If so hmmm. I'll definitely watch the watch connectivity video. That's one I haven't had the chance to see yet. Thanks!

setRegion should work fine on WKInterfaceMap, which I'm guessing is what you are using if it worked on watchOS1 and only required that line. You shouldn't need MKMapView or MKMapViewDelegate to do this. If you need the location then use Core Location as described in the WWDC video:


https://developer.apple.com/videos/wwdc/2015/?id=714


This is possible in the extension on the watch, so there is no need to use WatchConnectivity to get the location from the phone to the watch. It's worth watching the video anyway though.


The spinning wheel could be due to a lot of things. Have you checked that the region you are displaying is valid?

Hi, I am using Core Location to stream position data to me, and I just checked (print statement): the region is valid and as expected. I'm almost wondering whether it's a bug in the simualtor. Unfortunately the sim doesn't include standard Apple programs like their maps app, which could show me if maps are working at all on it. I'm a bit hesitant to try running it on my actual watch, but I might have to break down and do it. I even tried turning off streaming location data and only asking for the map once, but still no go--just a spinning wheel.


Thanks for the help. I thought maybe something else needed to be done, but sounds like I just need to display my region.

Just to check - do you have an internet connection on the machine with the simulator? If it can't get access to the internet then it wouldn't be able to display a map.

I do, yes. The phone app loads the map view just fine (including the actual map, not just the GPS location), and it is able to send locations to the watch sim. I will try to get it working on my actual watch and test. Will post the results here.

I am having this same issue. I set the Region and the Map View just displays a spinning indicator.


I have only been able to test on the simulator because Xcode wont allow me to run my app on the device as it just gives me a null reference to the Watch. (But that's another issue) 😟

I am experiencing the same spinning indicator like you were on the WKInterfaceMap like you were after calling setRegion. I have spent a few hours on it and could not get it resolved. Were you able to run it on the watch and get it to work? Was/ Is it a simulator bug?

Anybody have any update on this? I cannot get any map data to display on the WKInterfaceMap. Used to work just fine on watchos 1.0. In 2.0, all I can get is a pin, but no map actually loads despite calling setRegion to it

I was doing something similar, My WatchKit 1.0 displays a map using the MKMapSnapshotter with overlays and it updates every few seconds, This functionality is not possible with WKInterfaceMap as it doesn't allow overlays and fades out to black every time the map is updated (which looks awful when updating regularly).


The issue with creating a MKMapSnapshot on the phone and then transferring it to the watch is that in order for the MKMapSnapshotter to work it needs to be on a foreground thread (as stated in the MKMapSnapshotter documentation), this was not a problem when creating the snapshot on the watch with WK1.0 as the phone recognized that as a foreground activity and allowed the rendering of the snapshot.

I have had the snapshot render and send the image successfully, however this requires the phone to be running your app in the foreground, once the phone goes to sleep the updates stop, Which nullifies the point in a watch app if you need to have the phone awake all the time.


This also goes for the MKMapView as it too requires being on the foreground thread to render.


Hopefully apple see that this is an issue with MapKit and either allow the snapshotter to render on a background thread or update the WKInterfaceMap to support overlays and the ability to remove the rather annoying fade out animation.

I have the same Problem. Pin is shown but the map does not load. The map in the Maps apps also does not load (only using simulator). I don't understand why apple does not release a new beta since watchOS 2 is, in my opinion, still a mess. There are other things that do not work properly but thats another topic. Let's hope that the GM (should be released on 9. September) fixes all this.