How to launch the map inside some MapView

820 views
Skip to first unread message

Machete

unread,
Jan 21, 2011, 5:11:32 AM1/21/11
to mapsforge-dev
Hi Guys,

I'm with a simple problem and I dont know how to fix this, normally in
Google Maps I just place in my layout file a MapView with some ID on
it, but with mapsforge I don't know how to do it, I try several times
and in diferent ways but none of this ways works:

inside the code:

mapView = (MapView) findViewById(R.id.mapView); // don't work
mapView = (MapView) new MapView(this,
MapViewMode.OSMARENDER_TILE_DOWNLOAD).findViewById(R.id.mapView); //
don't work

------------------------------------------------------------------------------------------------
My layout XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
android:layout_width="fill_parent"
android:layout_height="15px"
android:text="@string/hello" />

<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<org.mapsforge.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>

</LinearLayout>
------------------------------------------------------------------------------------------------

Can anyone give me some light in terms of how I can place my map
inside some view in my layout?

Machete

unread,
Jan 21, 2011, 5:53:49 AM1/21/11
to mapsforge-dev
Let me explain in a simpler way:

I want to point my MapView to a LineaLayout already created inside my
layout.xml

Why this approach dont work?

mapView = new MapView(this,
MapViewMode.OSMARENDER_TILE_DOWNLOAD);
linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
linearLayout.addView(mapView);
setContentView(R.layout.main);

mueh...@inf.fu-berlin.de

unread,
Jan 26, 2011, 11:32:00 AM1/26/11
to mapsfo...@googlegroups.com, Machete
Hello Joao,

the problem is that you have to call "setContentView(R.layout.main)"
_before_ you can access the layout objects by ID. Otherwise, a call like
"findViewById(R.id.LinearLayout01)" (or R.id.mapView) will always return
null.

I have copied the source code that you provided into a new test
application, moved the setContentView() call to the top and it was
working. You may create the MapView either programatically via "new
MapView(...)" or in your XML layout file, both methods should work.

You can look at the source code of our "AdvancedMapViewer" demo
application to see an example how we work with XML layout files. The
Android application is in our repository in the following subdirectory:
trunk/Applications/Android/AdvancedMapViewer

By the way ... if you are using the MapView in a "download" mode, make
sure that your application has the permission to access the Internet.
For that you need to have the following line in your Manifest.xml file:
<uses-permission android:name="android.permission.INTERNET" />

Best regards,
Thilo

signature.asc

Machete

unread,
Jan 26, 2011, 11:41:26 AM1/26/11
to mapsforge-dev
Thanks Thilo,


Now works fine...


many thanks
Joao


On Jan 26, 4:32 pm, "muehlb...@inf.fu-berlin.de" <muehlb...@inf.fu-
>  signature.asc
> < 1KViewDownload

marko

unread,
Sep 17, 2012, 2:40:43 PM9/17/12
to mapsfo...@googlegroups.com, Machete
Hi
I'm trying to put my MapView in a RelativeLayout, but when I run the project I can see the map but I can not navigate on the map. The map does not move.
Can you help me please?

Thilo Mühlberg

unread,
Sep 17, 2012, 3:45:15 PM9/17/12
to mapsfo...@googlegroups.com
Try: mapView.setClickable(true);

Greetings,
Thilo
signature.asc

marko

unread,
Apr 29, 2013, 2:45:46 PM4/29/13
to mapsfo...@googlegroups.com, jmac...@gmail.com
Hello
Is there any way to put different file. Map as layers on a MapView?
For example berlin.map as a base layer and when the user click on any button to paint all schools in berlin (schools.map)?

Regards
Marco

Ludwig

unread,
May 6, 2013, 10:03:11 AM5/6/13
to mapsfo...@googlegroups.com
With the new rewrite architecture this is not difficult.

Technically, I believe you would be better off by implementing your schools-layer with markers (sooner or later you will have the ability again to click on markers), but it is also possible to do this with different tile layers generated from a map file.

You can render the same map file using different render themes (so one would show all the usual stuff, but not schools and maybe other things while a second render theme would only show schools. The second render theme needs to define the map-background as transparent #00000000 in the rendertheme.xml, otherwise it will hide everything underneath) and draw two layers on top of each other. You could then toggle the visibility of the layer using your button.

I have just pushed an example of how to do this onto my clone at http://code.google.com/r/ludwigbrinckmann-mapsforge/source/detail?r=d0cef725699d8711dc97ed419f0e3a2a5934b443&name=rewrite-samples

The examples you want to check out are RenderThemeMapViewer, which shows how to use a different render theme with the rewrite architecture, and then StackedLayersMapViewer which uses two layers rendered from the same map file on top of each other. In the /data directory of the Samples app are two render theme files that you need to put onto your devices /sdcard to run this. In this case a base layer with roads is overlaid with a layer for land use and buildings.

When you run this, you will notice that this is a pretty dirty implementation: I did not put any work into really deciding which part of the renderthemes to cut out, so you have partially obsured text. This could be done better, but then it would be more difficult to see that there are actually two layers.

HTH

Ludwig







--
You received this message because you are subscribed to the Google Groups "mapsforge-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapsforge-de...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages