Offline maps on your mobile with MGMaps
Tagged:  •    •  

For a little holiday to south-Germany I thought it would be handy to have some maps on my phone of the to-be-visited cities. Of course, I have Google Maps installed, but I'd rather not use it abroad due to the insane fees for data roaming. So after a little investigation I was able to have offline maps on my phone.

These are merely notes to myself, and it assumes you have a working J2ME enabled phone, a Linux PC (any other Unix like OS would do) and a working connection between PC and phone (USB, Bluetooth).

  1. Download and install Mobile GMaps. This is a Google Maps like application, but it supports other sources, like Yahoo Maps and OpenStreetMap. It cannot show Google Maps online, but you can use it as an offline source as we are going to do now. Make sure to download the signed JAD file. If you don't, the application will nag you everytime it has to read data from your phone's storage.
  2. We'll leave our phone alone for a moment and continue on our PC. We need two Perl scripts which are going to retrieve all the maps for us. You can find them here. They are called Map Tile Cacher (version 1.34) and MapTileFE (version 1.22). The latter is a frontend for the first script. Make sure these scripts are stored in the same directory.
  3. The frontend script needs input. I'll show what a script looks like which retrieves a part of the centre of Munich:
    GoogleMap
    13-16: 48.16434661372288, 11.4697265625 : 48.16801181636728, 11.6455078125
    13-16: 48.15335100578967, 11.4752197265625 : 48.16434661372288, 11.6455078125
    13-16: 48.138690195212064, 11.480712890625 : 48.15335100578967, 11.6455078125
    13-16: 48.16801181636728, 11.480712890625 : 48.17167701901168, 11.6400146484375

    It says to download 4 squares from Google maps. Each line shows a topleft and bottomright coordinate. It is prefixed by the zoom range. So each square is retrieved four times, for each zoom level.

    This may look a bit tedious to write, and it actually is. Fortunately, MapCacher.com is your friend. In a Google Maps interface you can mark the area which you wish to download. For cities, I prefer zoom levels from 13 to 16. Level 16 is detailed enough to read all street names.
    The level of detail applies to non-square areas. The more detail, the better it tries to approach your requested area. This means more (little) squares rather than one big square which may contain info you didn't ask for. Less detail is quicker and causes less requests to the map servers.
    Also choose the map type. Different kind of maps from different sources are available. For city trips, the option Google Road Maps suffices. Save the resulting *.map file into the directory where you stored the Perl scripts.

  4. Now it's time to run the MapTileFE script:
    $ chmod +x MapTileFE.pl
    $ ./MapTileFE.pl
    Following map files are available.
    Munchen, HongKong, Tokyo,
    Choose one of Map File:

    Enter the name of the input data you just generated and hit enter. Now all maps are retrieved, this could take quite a while with large maps and/or with many zoom levels. Make sure to read the warning below.

  5. When the script has finished, you'll see that a new directory appeared: MGMapsCache. This is supposed to go into your phone. Since I have additional storage I uploaded it into its root directory.
  6. Load the MGMaps application on your phone.
  7. (Optional) If you have downloaded two cities, MGMaps will center on one of these cities. But it may become a little difficult to locate the other city (assuming that you didn't retrieve the area between these two cities). While we're still in our own country, go online with MGMaps and locate these two cities and add them as favorite. Now we have the stored the coordinates such that we can locate our offline content quickly.
  8. MGMaps needs some slight configuration to actually make it use those stored maps. Go to the Menu, Settings, Map Browsing. Select the options Stored Maps and Offline Mode. The storage path should be set to E:/MGMapsCache if you stored the folder in the root of your additional storage.
  9. If you changed any settings in the previous step, restart MGMaps.
  10. You'll see that you're automatically located to your downloaded area. You can use the zoom levels you requested and move around just like you were online. It's done!

Warning
Map services don't seem to like it when many requests per second are being made (like the map cache scripts do). For instance, downloading two cities on Google Maps made me ending up on a blacklist for about 24 hours. You could hack in a sleep call into the frontend script to download a bit slower, at a rate that Google likes:

for ($Z = $Z1; $Z <= $Z2; $Z++) {
   open(CMD, "|perl MapTileCacher.perl");
   print CMD "$tiles_per_file\n$hash_size\n$MapType\n$Z\n$TopLeft\n$BottomRight\n\n";
   close(CMD);
+  sleep 5
}

Maybe 5 seconds is a bit excessive, but better safe than sorry.

Sources:

GMaps stored maps path

MGMaps is working fine when it is connected to Internet via WIFI. However, I would like to browse maps offline when you visit other cities/countries where connection to internet is not practical and the use of data plan would be very expensive.

I managed to follow your instructions to create a map file of the designated area and to generate tile files from my PC. These tiles files and directories are then copied to the phone (Blackberry 8320) using the Desktop Manager program.
After changing settings and storage path, the program could not find the destination (Error Searching) that I entered in the 'local search'.
I am not sure whether the error is caused by maps or the storage path setting. I have tried several combination but all are not working.
Here are the examples:
E:/MGMapsCache/Local/CA,
E:/SDCard/MGMapsCache/Local/CA,
/MGMapsCache/Local/CA,
/SDCard/MGMapsCache/Local/CA,

I would appreciate if your could help me in solving this issue. Thanks.

Local Search still requires

Local Search still requires internet access (using Google Maps). It does not mean that it searches locally in your memory, but it finds local places in a city. I'm not sure if offline searching is supported, as far as I can see it does not.

But maybe other readers of this page can correct me.