Show .map in assets folder

293 views
Skip to first unread message

Mario

unread,
May 20, 2012, 1:55:49 PM5/20/12
to mapsforge-dev
Hi, i have one question.

I show a map in my aplication, like that:

public class BasicMapViewer extends MapActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MapView mapView = new MapView(this);
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
mapView.setMapFile(new File("/sdcard/map1.map"));
setContentView(mapView);
}
}

But my map1.map is in the assets folder.

How can i do this?

Thanks

Miguel

unread,
May 20, 2012, 2:30:31 PM5/20/12
to mapsfo...@googlegroups.com
Hi Mario

Are you sure that the file is in SDCard. I believe not.

if i'm rigth, this can help:



2012/5/20 Mario <mari...@gmail.com>

Torello Querci

unread,
May 20, 2012, 5:31:59 PM5/20/12
to mapsfo...@googlegroups.com
Hi,

I have the same problem. I put the map file into /res/raw folder but is not copied into the private folder.

To try to solve this problem I made the following action:
1 - rename the map file to *.map.mp3 because in this way the file is stored uncompressed, 
2 - when the app start I check for SD availability.
3 - If SD is present I looking for map file. If the file is missing I copy from resource to external file 
4 - I specify the new filename to MapView object with setMapFile method.

Ok, is no a linear way but in my test semms to work.


Best Regards

2012/5/20 Miguel <bka...@gmail.com>

Mario

unread,
May 22, 2012, 5:41:43 AM5/22/12
to mapsforge-dev
I couldn't solve yet. Any solution?

It's possible show the map in assets o raw or it's compulsory that the
map is in sd card?

On May 20, 11:31 pm, Torello Querci <tque...@gmail.com> wrote:
> Hi,
>
> I have the same problem. I put the map file into /res/raw folder but is not
> copied into the private folder.
>
> To try to solve this problem I made the following action:
> 1 - rename the map file to *.map.mp3 because in this way the file is stored
> uncompressed,
> 2 - when the app start I check for SD availability.
> 3 - If SD is present I looking for map file. If the file is missing I copy
> from resource to external file
> 4 - I specify the new filename to MapView object with setMapFile method.
>
> Ok, is no a linear way but in my test semms to work.
>
> Best Regards
>
> 2012/5/20 Miguel <bkat...@gmail.com>
>
>
>
>
>
>
>
> > Hi Mario
>
> > Are you sure that the file is in SDCard. I believe not.
>
> > if i'm rigth, this can help:
>
> >http://androideity.com/2011/11/03/escribiendo-archivos-en-la-memoria-...
>
> > 2012/5/20 Mario <mariof...@gmail.com>

Sebastian Fischer

unread,
May 22, 2012, 10:06:27 AM5/22/12
to mapsfo...@googlegroups.com
> It's possible show the map in assets o raw or it's compulsory that the
> map is in sd card?

Mapsforge needs random access but assets or raw data can only be
accessed as an InputStream. You need to copy your map file to internal
or external storage in order to access it using mapsforge.

Sebastian

Torello Querci

unread,
May 22, 2012, 10:09:06 AM5/22/12
to mapsfo...@googlegroups.com
Thanks Sebastian,

so we have two choice:
1 - bring the map in asset and at the first run, write out to internal or external storage (ok for small map)
2 - download it from web at the first run


Best Regards

2012/5/22 Sebastian Fischer <federigo....@gmail.com>

Sebastian Fischer

unread,
May 22, 2012, 10:17:33 AM5/22/12
to mapsfo...@googlegroups.com
> so we have two choice:
> 1 - bring the map in asset and at the first run, write out to internal or
> external storage (ok for small map)
> 2 - download it from web at the first run

Exactly. Consider zipping the map file and unzipping it on the device
if you are concerned about download speed. In my case it saves between
20 and 30% of space. (I use gzip for packing and a GZIPInputStream for
unpacking.)

Sebastian

Mario

unread,
May 22, 2012, 12:19:48 PM5/22/12
to mapsforge-dev
thanks!

On May 22, 4:17 pm, Sebastian Fischer <federigo.pescat...@gmail.com>
wrote:

joshas

unread,
May 23, 2012, 8:35:11 AM5/23/12
to mapsfo...@googlegroups.com
If your map file is bigger than 1MB, you'll need to split it before putting to assets directory.

Torello Querci

unread,
May 23, 2012, 8:43:01 AM5/23/12
to mapsfo...@googlegroups.com


2012/5/23 joshas <jos...@gmail.com>

If your map file is bigger than 1MB, you'll need to split it before putting to assets directory.


At the moment I use the bremen,map file for testing, that is about 3MB, and works if I rename as bremen.map.mp3 file in the /res/raw folder. In this way seems that the 1MB limit size is gone. When I store it as bremen.map I not able to recover it.

When the file is write on SD I rename as bremen.map and all seems to be ok. I not test it on real phone.


Best Regards

Reply all
Reply to author
Forward
0 new messages