I’m developing an app to be used where data signals are either very weak or completely off. I want the user to see his walked path on the screen, as he moves from one GPS corner to the next. It’s easy to do with the map showing, but I want to it with the map hidden/not loaded. When the user enters a wifi or 3G area, the map should appear as usual with the position points/path as an overlay.
It would be great if there is an easy way to do this!
I can’t immediately think of an easy way, but a few possible approaches come to mind, in the order I would personally try them:
Make your own overlay class which covers the whole map and for which you can make the background opaque when desired. I haven’t worked with MapKit in a long time and am not up on changes in the last couple of SDK releases, so I’m just spitballing here…but if you can get this to work, it’s probably the easiest way. You might have to perform a hack or two.
Use a third-party mapping SDK like this one. I have no experience using this nor any other besides Google’s (a few years ago at that) but you may be able to find one that supports what you want to do without too much headache. Of course, then you’re potentially losing out on MapKit functionality that you might have liked to include.
Draw your overlay on a UIView subclass using Quartz/Core Graphics. You could definitely get this to work, but you’re going to have to do a fair bit of math in order to convert back and forth between map coordinates and screen coordinates to do your drawing.
Subclass MKMapView and superimpose an ‘overlay-only’ custom map view on top of a ‘normal’ one. Your subclass would simply handle drawing the overlay, without displaying any map content. This is pretty hack-ish, though, and might not work at all. MKMapView does inherit from UIView, and might override drawRect: in order to draw its map content, in which case you could override drawRect: in your subclass and (possibly) just draw your overlay(s) without any map content. But quite possibly not. I don’t have time to investigate further, but it should be pretty easy to find out whether this is a dead end.
Good luck! Hopefully this is enough to at least get you started. Let me know if you need additional help.
Thanks a lot! I think I like your third suggestion best. It’ not too hard to convert the GPS coords to cartesian xy coords and scale them in meters. From there scaling to screen points should be doable! You’ll have to watch if the user walks off-screen though… When the user is back to wifi or 3G coverage, one can go back to MapKit and plot on the map.
I think the easiest way to do this might be to look into MKTileOverlay. You can use MKMapKit and get the easy user tracking you are used to but you can supply your own map tiles, which can be anything you like. Returning a solid colour or other background as map tile should be very, very simple. There’s some good information on NSHipster.
Hello, @olofhess did you manage to solve it? I need something like that.
@magonicolas I will try MKTileOverlay, but haven’t got around to it yet. Will post here if/when I have some news.
ok, thanks, let me know if you try it!