OpenStreetMap on the iPhone!

The iPhone is amazing. And the Maps application is pretty special. Only problem with it is that Google Maps is the only available data source. Well I’ve just been working on that. Now, there’s OpenStreetMap on the iPhone

OSM Central London on the iPhone
OSM Isle of Wight on the IPhone

These are screenshots of OpenStreetMap tiles, viewed in the native iPhone Maps application. Wooooooo

How you can do it

So it’s pretty easy to try it out. You’ll need to have jailbreak’d your phone (I used iBrickr, there’s plenty of other methods out there, even for 1.1.1). Download the maps tile cache db, and copy it over to your phone, using scp or whatever. The tile cache db is about 30 MB, so please only download if you’re going to try it. Also, I’ve had the Maps App crash occasionally when browsing the Maps, though nothing fatal .. so use at your own risk.


download http://brainoff.com/media/LondonZ17.sqlitedb

cp to /var/root/Library/Caches/MapTiles/MapTiles.sqlitedb on your phone

restart your phone

How its done

My first idea was to modify the configuration or constant that the Maps App used for constructing Google Maps tile requests. Andrew helped with decompiling and pointers to other files, but we had no luck as yet. But looking at the app or at the GMM module in a hex editor, there appeared to be SQL inserts of tile pointers .. perhaps Maps was using a database to cache requested tiles. Searching through the filesystem found MapTiles.sqlitedb. That db has just two tables..


sqlite> .schema
CREATE TABLE images(zoom int, x int, y int, flags int, length int, data blob);
CREATE TABLE version(version int);
CREATE INDEX index1 on images (zoom,x,y,flags);

images was simply storing the zoom, x, and y of each tile. flags was set to ’2′ for street maps, ’3′ for aerial imagery. length appeared to be the size of the data blob. And data was the png. So simply adding new rows to this table, with OpenStreetMap tiles rather than Google, would have the Map app using OSM.

I needed to grab a bunch of OSM tiles. Asked on #osm, and Almien helpfully contributed a script to download all tiles on a zoom level within a bbox.

And I needed to easily insert BLOBs of the tile pngs into the sqlite db. This sqlite tutorial had just the right code, eatblob.c. I wrote a script which walked through the directory of downloaded tiles, and insert each one into a copy of MapTiles.sqlitedb. All of central London at zoom 18 took a while to download and insert, and came out at 60 MB.

Actually, there’s nothing particularly OSM about this method. Could download Yahoo or Multimap or yea Google tiles, and stuff them into the cache db.

Issues

There are the crashes I mentioned. Haven’t debugged this yet, but I figure this is surmountable. Perhaps the file size of the tiles are too large.

The Maps App zoom levels are off by one. What it calls zoom level 13, are actually being tiled as if it was zoom level 14.
(zoom off by 1). Perhaps the tiles on the iPhone are half the width and height of normal tiles? I haven’t looked into this and its late, so I don’t even know if that’s a plausible explanation.

There’s still a little Google logo in the lower left corner, need to replace that too!

Last thing, don’t know how the cache is refreshed. It’s not going to grow without bound — when and why are things expired from the cache?

Other Methods

There are probably better ways to do this. One would be to modify the Map.app binary, or whatever module or library or configuration file that stores the url or ip address used when constructing requests for Google Maps tiles, and modifying that to request directly from OSM. Or write a provider independent version of the Map App — tiling seems to be part of a core library in the phone, it looks like Safari uses the same stuff to zoom in and out on web pages. If anyone starts looking into this, drop me a line.

14 Comments

  1. John said,

    October 19, 2007 @ 8:48 am

    This is really nice, ISTR that the mobile versions of google maps do use half size tiles so you might want to try playing with cutting up the OSM tiles first. Great job though anyway, wish I had an iPhone to try it on!

  2. High Earth Orbit » Blog Archive » OpenStreetMap on the iPhone said,

    October 19, 2007 @ 12:41 pm

    [...] Mikel was inspired to put free data on his iPhone – so he figured out how to use OpenStreetMap on his iPhone Maps Application. [...]

  3. jeepx.net » Blog Archive » USGS Delivers GeoPDF said,

    October 20, 2007 @ 8:05 am

    [...] OpenStreetMap for iPhones may be down but it was a post on how to make use of the free map database. Meanwhile check the news from that side of the Atlantic. [...]

  4. openstreetmap on your iphone « thinkwhere said,

    October 21, 2007 @ 7:58 pm

    [...] openstreetmap on your iphone October 21, 2007 at 7:58 pm | In Mapping, geo, openstreetmap | Tags: openstreetmap iphone maps We joked about it at State of the Map (before the iphone was released) and now Mikel and Andrew hacked the iphone to display openstreetmap tiles! Cool! Turns out, the phone helpfully caches map tiles in a sqllite database on the phone. [...]

  5. Fernando Quadro » Blog Archive » OpenStreetMap no iPhone said,

    October 21, 2007 @ 8:06 pm

    [...] Fonte: Brain Off (No Ratings Yet)  Loading … [...]

  6. Changing the tiles on the iPhone Maps application on devphone said,

    October 23, 2007 @ 4:26 am

    [...] Mikel Maron hacked the iPhone Maps application to allow him to put in different tiles, in this case those of OpenStreetMap. [...]

  7. a work on process » links for 2007-10-23 said,

    October 23, 2007 @ 5:25 am

    [...] Brain Off » OpenStreetMap on the iPhone! Very nice. Now if O2 just had a decent data plan available, an iPhone might be tempting. As it is, I’m probably going to pick up an N95 this week (tags: iphone mapping neogeography openstreetmap) [...]

  8. ian said,

    October 23, 2007 @ 5:32 am

    yeah! great work mikel (and andrew)!

  9. The Gungle» Blog Archive » links for 2007-10-23 said,

    October 23, 2007 @ 9:22 am

    [...] Brain Off » OpenStreetMap on the iPhone! (tags: iphone maps hack OpenStreetMaps) [...]

  10. Nick said,

    October 24, 2007 @ 2:39 am

    Do you think that the map app crashes are something specific to the tiles you placed in the DB, or simply the app being flaky? I’ve fiddled with an iPhone and iPod Touch in an Apple store, the map app died on me 3 times in ~5 minutes. It struck me as an interesting and useful program, but quite unstable.

  11. mikel said,

    October 24, 2007 @ 8:53 am

    Nick — a bit of both.

    The tiles I used are not the standard size used on the iPhone. The iPhone uses tiles 128×128 tiles, but standard web map tiles are 256×256. I think fixing this should result in less crashes.

    There could also be something with the size of the cache. I’m still not clear on how the cache is managed.

    Besides that, the App is a bit flaky. I haven’t seen that much failure in “normal” mode. But I have seen the App crash in the middle of a demo by Michael Jones!

  12. BlinkGeo » Wednesday Lunch Time Geo Links - 10-24-2007 said,

    October 24, 2007 @ 8:49 pm

    [...] OpenStreetMap on the iPhone! [...]

  13. edparsons.com » Blog Archive » OSM on the iPhone.. not in Dubai !! said,

    October 28, 2007 @ 12:28 am

    [...] Of course I took my laptop along to keep up with email and stuff, and was thus quite impressed to see Mikel’s post about getting OSM onto the maps application on the iPhone ! [...]

  14. Brook said,

    November 2, 2007 @ 11:50 am

    Fantastic!
    I live in Sydney. Any way of doing this for NSW or anyother part of the database?

RSS feed for comments on this post · TrackBack URI

Comments (14)