Mobile Map API

MGMaps Lib SDK is professional toolkit to develop mobile mapping applications.
Platforms: iPhone, Android, RIM BlackBerry, Java ME (J2ME)
Download maps API SDK »

Latest news

Last at Thu, 29 Jul 2010 19:38:21
Topic: New maps SDK release 1.1.0
See more news »

Nutiteq on Twitter

6 weeks 1 day ago Nutiteq is proud sponsor of StateOfTheMap 2010 #sotm10

Nutiteq with maps OFFLINE

34 replies [Last post]
mveggia
User offline. Last seen 43 weeks 6 days ago. Offline
Joined: 06/10/2009

Hi to all. I'm trying to use mgmaps lib sdk with netbeans. I want to set my app to load maps from local resources (offline) and not from online resources but I don't know how can I do it. There is someone who can illustrate my step by step how can i include offline maps to my app? (for example: Italy)
Thanks!

jaak
User offline. Last seen 3 hours 55 min ago. Offline
Joined: 06/19/2008

It depends on from where do you want the maps. For e.g. openstreetmap for Italy you (actually end-user) must download a tile package to phone's memory card. For this there are some guides at http://www.mgmaps.com/cache/

Actual code in application is quite simple (assuming that maps are copied to the /maps directory):

final StoredMap sm = new StoredMap("OpenStreetMap", "/maps", true);
mapComponent.setMap(sm);

You may want to have your own custom graphics (color or image) for missing tiles. Add following lines between code lines above to set own color.

final Image missing = Image.createImage(sm.getTileSize(), sm.getTileSize());
final Graphics graphics = missing.getGraphics();
graphics.setColor(0xFFCCCECC);
graphics.fillRect(0, 0, sm.getTileSize(), sm.getTileSize());
sm.setMissingTileImage(missing);

Also the library has sample "storedmaps" which includes also file directory browser function. You can use this as a base.

/JaakL

mveggia
User offline. Last seen 43 weeks 6 days ago. Offline
Joined: 06/10/2009

I've an error using

final StoredMap sm = new StoredMap("OpenStreetMap", "/maps", true);

highlighting "StoredMap" after "new".

Cannot find symbol
Symbol: costructor StoredMap(java.lang.String,java.lang.String,boolean)
Location: class com.nutiteq.maps.StoredMap

What can I do?

jaak
User offline. Last seen 3 hours 55 min ago. Offline
Joined: 06/19/2008

Did you add import?
import com.nutiteq.maps.StoredMap;

/JaakL

jaak
User offline. Last seen 3 hours 55 min ago. Offline
Joined: 06/19/2008

Also check if you have proper library version (1.0.0) in build path, not some older one.

/JaakL

mveggia
User offline. Last seen 43 weeks 6 days ago. Offline
Joined: 06/10/2009

Yes I did

mveggia
User offline. Last seen 43 weeks 6 days ago. Offline
Joined: 06/10/2009

I solve my question "Cannot find symbol" upgrading the lib from 0.1.0 to 1.0.0.

Now I use this site
http://www.mapcacher.com/
for get a .map file (size is less than 1kb) for indicate what area I want.

Then I use this file with gMapMaker app (http://www.mgmaps.com/cache/gMapMaker-setup.exe) to download all data and the program make a folder cache with some folders (example OpenStreetMap_0, OpenStreetMap_1, ...). I put all of these folders into /maps in res directory of my project. Then i use

final StoredMap sm = new StoredMap("OpenStreetMap", "/maps", true);
mapComponent.setMap(sm);

And i try my application without connect to internet but i see only red color without map data.

What's wrong? can you help me?

jaak
User offline. Last seen 3 hours 55 min ago. Offline
Joined: 06/19/2008

There are two a bit different formats for stored maps:
a) in JAR file (res directory) the files should be named as {zoom}_{x}_{y}.png , without subdirectories. Everything in single directory. This is for small number of files (few MB), and each tile must be in own file, as it is not suggested to make too huge JAR files for applications.

b) in file system of phone or flash drive you should use file structure like gmapmaker uses (with .mgm files). There are subdirectories also. This is for large number of files (up to few GB), and it supports multiple tiles per one file format.

You can convert tiles from the "mgmaps" file format to JAR file simpler format, it is mainly just matter of file naming and directory flattening. We do not have specific script for it, but it is easy to do it. Anyway too large JAR file should be avoided.

/JaakL

jaak
User offline. Last seen 3 hours 55 min ago. Offline
Joined: 06/19/2008

ps. to use files from JAR file you should use following code instead StoredMap (set zoom levels depending on your content):
mapComponent.setMap(new JaredOpenStreetMap(256, 1, 11));

/JaakL

mveggia
User offline. Last seen 43 weeks 6 days ago. Offline
Joined: 06/10/2009

I've created the structure with .mgm files and all of these files/directories in one directory called "OpenStreetMap". Now how can I import these maps in my application? can you explain me the method step by step? (with code and various step)
Thanks

jaak
User offline. Last seen 3 hours 55 min ago. Offline
Joined: 06/19/2008

The library package has two sample codes:
a) samples\mapper\src\com\nutiteq\storedmaps : about using .mgm files from phone memory or flash drive (file system). This shows also how enduser can browse to find correct directory

b) samples\mapper\src\com\nutiteq\jarmap : about maps in JAR file. The library samples\mapper\resources directory has also maps (png files) in correct format.

If you want to use .mgm files, then you have to make sure that these are "one tile per file" and you have to rename them to .png. You can check with a picture viewer if these are correct png files. .Mgm is a file format which may have one png file (then you can just rename it) or could have several ones.

/JaakL

mveggia
User offline. Last seen 43 weeks 6 days ago. Offline
Joined: 06/10/2009

I use "jar method" and it works.
With storedmaps i've some problems. I use the file browser like the sample samples\mapper\src\com\nutiteq\storedmaps and finally i use

mapItem.setMap(sm);

But i don't see the map..

the sample uses mapComponent. Is there problems if I use mapItem?

mveggia
User offline. Last seen 43 weeks 6 days ago. Offline
Joined: 06/10/2009

I solve it.

dalbani
User offline. Last seen 43 weeks 1 day ago. Offline
Joined: 08/24/2009

Hello,

On the same "offline maps" topic, I was wondering if it was supported on the Android platform.
So far I could only get red tiles with stored maps... while it does work correctly with, say, Cloudmade maps.

If I have a directy called "GoogleMap_14" (i.e. zoom 14) containing .mgm files, how should I call the StoredMap constructor ?
Currently I have this in my code:

StoredMap storedMap = new StoredMap("GoogleMap", "/sdcard/maps", false);

where the directory full path is "/sdcard/maps/GoogleMap_14", and I do request a level 14 zoom in the BasicMapComponent constructor.

So what did I do wrong?

Plus I was thinking of the filesystem-related issue. I've tried to implement a JavaIO-based implementation of FileSystem(Connection) for Android but I'm not sure that I'm in the "correct direction" :-)

Any help would be welcome!

Thanks.

jaak
User offline. Last seen 3 hours 55 min ago. Offline
Joined: 06/19/2008

Yes, you would need to implement FileSystem for Android (i.e. Java IO). Unfortunately library does not include it yet. Probably it will be in the next update.

/JaakL

dalbani
User offline. Last seen 43 weeks 1 day ago. Offline
Joined: 08/24/2009

You're right, I've implemented the FileSystem stuff and it does now work.

FileSystem.readFile(filename) is called an argument like 'sdcard/maps/GoogleMap_14/507_359.mgm|10_4'.
So I can extract the filename part and then parse the .mgm file to get the right tile according to the dx/dy.
By the way, it's not a big deal, but what is the reason of the missing leading '/' in the file path? As I do have implemented FileSystem.getRoots() as returning a single "/" in a Vector.

Thanks

Matrix
User offline. Last seen 47 weeks 1 day ago. Offline
Joined: 08/21/2009

Hi,
Where I can download Stored map of Uzbekistan?

Matrix
User offline. Last seen 47 weeks 1 day ago. Offline
Joined: 08/21/2009

Now I download stored map of Estonia.
How can I import these maps in my application.

jaak
User offline. Last seen 3 hours 55 min ago. Offline
Joined: 06/19/2008

For Stored maps creation see some guides from http://www.mgmaps.com/cache/

For using the maps you copy them to the phone (SD card usually), e.g. directory maps, uncompressed. Then set map type in your code as stored map:

mapComponent.setMap(new StoredMap("OpenStreetMap", "/Memory card/maps", true));

See sample "com.nutiteq.storedmaps" in j2me SDK package. This creates also directory browser for user, so maps directory can be found interactively. On different phones SD card root directory can be named differently, this "Memory card" used in N95 for example.

/JaakL

Larry101
User offline. Last seen 44 weeks 6 days ago. Offline
Joined: 09/15/2009

I have the same problem as those mentioned above. I downloaded the Estonia Maps, unzipped them, put them in a folder called maps in the mass memory of my N95 8GB. The stored maps example works fine when I select the folder using the file browser implemented. But as soon as I try and skip this step, and just hard code the url to the files, the maps don't load (just get red screen). I have tried both:
mapComponent.setMap(new StoredMap("OpenStreetMap", "/Mass memory/maps", true));

and

mapComponent.setMap(new StoredMap("OpenStreetMap", "/E:/maps", true));

but neither works. The log shows a lot of "Could not retrieve E:/maps/OpenStreetMap_1/1.0.mgm" type errors.

Larry101
User offline. Last seen 44 weeks 6 days ago. Offline
Joined: 09/15/2009

To answer my own question, in case anybody else ever has this problem, the following advice in the Javadocs for the library fixed my problem:
Note: to use stored map You need to also insert FileSystem into map component using BasicMapComponent.setFileSystem(FileSystem)

relliknomed
User offline. Last seen 42 weeks 4 days ago. Offline
Joined: 09/03/2009

I need enough information about develop an offline maps application(Android) you could give me information, tutorials or an example about develop offline maps application please help me thanks.

doraenino
User offline. Last seen 15 weeks 5 days ago. Offline
Joined: 12/27/2009

I try to used stored maps on my Android app.
I have download the stored map by gMapMaker and I have copied it to sdcard (mgmaps/OpenStreetMap_01,
OpenStreetMap_02 ...)

mapComponent.setFileSystem(new AndroidFileSystem());
mapComponent.setMap(new StoredMap("OpenStreetMap",
"/sdcard/mgmaps", true));

But i only see the red. In logCat i don't see anything. What did I do wrong ?

jaak
User offline. Last seen 3 hours 55 min ago. Offline
Joined: 06/19/2008

You should get logs to get some hints. Turn on logging of the library:

Log.setLogger(new AndroidLogger("NutiteqLib"));
Log.enableAll();

/JaakL

doraenino
User offline. Last seen 15 weeks 5 days ago. Offline
Joined: 12/27/2009

Thanks you, I solved it.
The problem is gMapMaker downloads the stored map and put mgm files into child folder (0,1,2...). I copy these files and put all of them in a folder and it works fine.

tanmay
User offline. Last seen 5 weeks 5 days ago. Offline
Joined: 05/14/2010

How did u flatten the directory structure?? Have you got the script in case you used one ? I am having the same problem. WOuld appreciate your help.

Cheers

rastakais
User offline. Last seen 19 weeks 3 days ago. Offline
Joined: 03/14/2010

hi every one;
i ask how make google map with LWUIT lib in j2me??
I'm stuck :( is there somebody who can help me !!!

jaak
User offline. Last seen 3 hours 55 min ago. Offline
Joined: 06/19/2008

I don't want to know how to make Google map (as it is not legal).

Regarding LWUIT see http://www.nutiteq.com/maps_lwuit.html . I just updated it and added also a basic sample project with source and compatible LWUIT and Nutiteq libraries.

/JaakL

sasquatchsoftware
User offline. Last seen 8 weeks 5 days ago. Offline
Joined: 05/10/2010

hi jaak,

I am using the api for blackberry, going the StoreMap path (not jar). But i have also realized all my mgm files are put into child folder (0,1,2...).

ie: \maps\OpenStreetMap_0\0\0_0.mgm

I know this is the folder naming setting for multiple tiles per file. But according to its cache.conf, it should be 1tile per file: version=3
tiles_per_file=1
hash_size=97
center=42.525564,-90.000000,1,OpenStreetMap

Is there a way to download the mgm images again but put in the same zoom folder instead of MTPF folder format? Thanks.

==============

Darn, i think that wasn't the only problem. I tried the method that doraenino used by copying all the files from the child directory into one folder, and it still doesn't work.

I logged the errors:
Error > Error in task runner: null
No stack trace
Debug > TW: create new worker
Error > Error reading tile: null
No stack trace
Error > Could not retrieve maps/OpenStreetMap_3/1_2.mgm
Error > Error reading tile: null
No stack trace
Error > Error reading tile: null
No stack trace
Error > Could not retrieve maps/OpenStreetMap_3/0_3.mgm
Error > Could not retrieve maps/OpenStreetMap_3/0_2.mgm
Error > Error reading tile: null
No stack trace
Error > Error reading tile: null
No stack trace
Error > Error reading tile: null
No stack trace
Error > Could not retrieve maps/OpenStreetMap_3/1_2.mgm
needRepaint complete=false
Error > Could not retrieve maps/OpenStreetMap_3/0_3.mgm
Error > Could not retrieve maps/OpenStreetMap_3/0_2.mgm
needRepaint complete=false
needRepaint complete=false

It seems it couldn't find the file, even though i already put the files in the sdcard, ie. G:\maps\OpenStreetMap_3, etc.

sasquatchsoftware
User offline. Last seen 8 weeks 5 days ago. Offline
Joined: 05/10/2010

also tried using
final StoredMap openStreet = new StoredMap("OpenStreetMap", "/SDCard/maps", true);
and
final StoredMap openStreet = new StoredMap("OpenStreetMap", "/sdcard/maps", true);
neither work on simulator or actual device.

im really stuck now. any suggestions?

sasquatchsoftware
User offline. Last seen 8 weeks 5 days ago. Offline
Joined: 05/10/2010

After implementing FileSystem with JSR75FileSystem fs = new JSR75FileSystem();
mapComponent.setFileSystem(fs);
I get another another kind of error. Looks like this time it's actually accessing the right folder and file name. Still having error reading the images and the cache.conf file. What am I missing?

Debug > Loading file:///SDCard/maps/cache.conf
CMM: OilTraxNT(1340) no sig from 0x33
CMM: OilTraxNT(1340) no sig from 0x33
Error > Error reading cache.conf
No stack trace
Debug > Loading file:///SDCard/maps/OpenStreetMap_6/10_22.mgm
CMM: OilTraxNT(1340) no sig from 0x33
Error > Error reading tile: File system error
No stack trace
Error > Could not retrieve SDCard/maps/OpenStreetMap_6/10_22.mgm
Debug > Loading file:///SDCard/maps/OpenStreetMap_3/1_3.mgm
CMM: OilTraxNT(1340) no sig from 0x33
Error > Error reading tile: File system error
No stack trace
Error > Could not retrieve SDCard/maps/OpenStreetMap_3/1_3.mgm
Debug > Loading file:///SDCard/maps/OpenStreetMap_3/1_2.mgm
CMM: OilTraxNT(1340) no sig from 0x33
Error > Error reading tile: File system error
No stack trace
Debug > Loading file:///SDCard/maps/OpenStreetMap_3/0_3.mgm
CMM: OilTraxNT(1340) no sig from 0x33
Error > Error reading tile: File system error
No stack trace
Error > Could not retrieve SDCard/maps/OpenStreetMap_3/1_2.mgm
Error > Could not retrieve SDCard/maps/OpenStreetMap_3/0_3.mgm
Debug > Loading file:///SDCard/maps/OpenStreetMap_3/0_2.mgm
CMM: OilTraxNT(1340) no sig from 0x33
Error > Error reading tile: File system error
No stack trace
Debug > Loading file:///SDCard/maps/OpenStreetMap_3/1_3.mgm
CMM: OilTraxNT(1340) no sig from 0x33
Error > Error reading tile: File system error
No stack trace
Debug > Loading file:///SDCard/maps/OpenStreetMap_3/1_2.mgm
CMM: OilTraxNT(1340) no sig from 0x33
Error > Error reading tile: File system error
No stack trace
Debug > Loading file:///SDCard/maps/OpenStreetMap_3/0_3.mgm
CMM: OilTraxNT(1340) no sig from 0x33
Error > Error reading tile: File system error
No stack trace
Error > Could not retrieve SDCard/maps/OpenStreetMap_3/0_2.mgm
Error > Could not retrieve SDCard/maps/OpenStreetMap_3/1_3.mgm
needRepaint complete=false
Error > Could not retrieve SDCard/maps/OpenStreetMap_3/1_2.mgm
Error > Could not retrieve SDCard/maps/OpenStreetMap_3/0_3.mgm
Debug > Loading file:///SDCard/maps/OpenStreetMap_3/0_2.mgm
CMM: OilTraxNT(1340) no sig from 0x33
Error > Error reading tile: File system error
No stack trace
Error > Could not retrieve SDCard/maps/OpenStreetMap_3/0_2.mgm
needRepaint complete=true

jaak
User offline. Last seen 3 hours 55 min ago. Offline
Joined: 06/19/2008

The file format for 1 tile per file should be /_/_.mgm . There is middle directory level if there is hash_size>0. You have hash_size=97, so this means that files are spread to up to 97 subdirectories (just to avoid too large dir listings), and also tile reader tries to read them from there. You probably want to use setting hash_size=0.

Your another issue comes from file reading in general, cache.conf . BlackBerry is not too generous with debug info, but I suspect that there is something wrong about permissions (does app have file read permissions?) or root directory should be defined differently.

/JaakL

sasquatchsoftware
User offline. Last seen 8 weeks 5 days ago. Offline
Joined: 05/10/2010

thanks jaak.

I got it to work eventually. In end, filesystem was causing all the problems. After correctly setting the filesystem, the naming of the files it tries to fetch from is correctly parsed in the hash97 fashion (ie. /_/_.mgm ).

my code looks like this:
final StoredMap openStreet = new StoredMap("OpenStreetMap", "/SDCard/maps", true);
JSR75FileSystem fs = new JSR75FileSystem();
map.setFileSystem(fs);

shamitha
User offline. Last seen 7 weeks 17 hours ago. Offline
Joined: 04/11/2010

Hi,
I am trying to use the stored maps to display maps offline. I tried the sample from library maps-lib-j2me-1_0_2. I stored the maps obtained from gmapmaker in "maps" directory in res folder of my project. When i tried executing MapCanvas midlet, it shows me an exception on emulator saying: "Application cannot be launched. The application may have done an illegal operation. Contact the provider to resolve the issue. Class is not a midlet".
On the output window it shows the following error:
java.lang.InstantiationException: Class not a MIDlet
- com.sun.midp.main.CldcMIDletLoader.newInstance(), bci=41
- com.sun.midp.midlet.MIDletStateHandler.createMIDlet(), bci=66
- com.sun.midp.midlet.MIDletStateHandler.createAndRegisterMIDlet(), bci=17
- com.sun.midp.midlet.MIDletStateHandler.startSuite(), bci=27
- com.sun.midp.main.AbstractMIDletSuiteLoader.startSuite(), bci=52
- com.sun.midp.main.CldcMIDletSuiteLoader.startSuite(), bci=8
- com.sun.midp.main.AbstractMIDletSuiteLoader.runMIDletSuite(), bci=161
- com.sun.midp.main.AppIsolateMIDletSuiteLoader.main(), bci=26
Also, in storedMapSample, I get an error as:
java.io.IOException
- javax.microedition.lcdui.ImageDataFactory.createImageFromStream(), bci=8
- javax.microedition.lcdui.ImageDataFactory.createResourceImageData(), bci=45
- javax.microedition.lcdui.Image.createImage(), bci=8
- com.nutiteq.storedmaps.MapCanvas.(), bci=12
- com.nutiteq.storedmaps.StoredMapSample.startApp(), bci=15
- javax.microedition.midlet.MIDletTunnelImpl.callStartApp(), bci=1
- com.sun.midp.midlet.MIDletPeer.startApp(), bci=7
- com.sun.midp.midlet.MIDletStateHandler.startSuite(), bci=269
- com.sun.midp.main.AbstractMIDletSuiteLoader.startSuite(), bci=52
- com.sun.midp.main.CldcMIDletSuiteLoader.startSuite(), bci=8
- com.sun.midp.main.AbstractMIDletSuiteLoader.runMIDletSuite(), bci=161
- com.sun.midp.main.AppIsolateMIDletSuiteLoader.main(), bci=26
TRACE: , Exception caught in Display class
java.lang.NullPointerException: 0
- com.nutiteq.storedmaps.MapCanvas.paint(), bci=53
- javax.microedition.lcdui.CanvasLFImpl.uCallPaint(), bci=202
- javax.microedition.lcdui.Display$ChameleonTunnel.callPaint(), bci=33
- com.sun.midp.chameleon.layers.BodyLayer.paintBody(), bci=12
- com.sun.midp.chameleon.CLayer.paint(), bci=46
- com.sun.midp.chameleon.CWindow.paintLayers(), bci=115

please help me detect the bugs.
Thanks!!
Really appreciate any help!!

jaak
User offline. Last seen 3 hours 55 min ago. Offline
Joined: 06/19/2008

The first error is that something is wrong with your project or building, so the package is not correct Midlet. Can't tell what could be there.

The second issue is IOException. It means that midlet cannot read map file (directory). Maybe permission in JAD file missing, maybe defined file directory is wrong.

/JaakL