add marker on map using mapsforge

2,008 views
Skip to first unread message

arra...@gmail.com

unread,
Mar 3, 2017, 10:29:21 PM3/3/17
to mapsforge-dev
hello, im newbie in android dev. now, i want build some map app using mapsforge. i just following this step https://github.com/mapsforge/mapsforge/blob/master/docs/Getting-Started-Android-App.md and now i want to add marker on LatLong. can anyone help me or explain how to show it ? sorry for may bad english

Emux

unread,
Mar 4, 2017, 4:55:34 AM3/4/17
to mapsfo...@googlegroups.com
You can study mapsforge-samples-android collection of Mapsforge examples which show how to use its API in various cases.

Specifically for overlays (like markers) the related example is OverlayMapViewer.

--
Emux
Message has been deleted

Emux

unread,
Mar 7, 2017, 2:57:01 AM3/7/17
to mapsfo...@googlegroups.com
On 07/03/2017 09:07 πμ, arra...@gmail.com wrote:
thanks for answer for my question. can i ask you another question ? now i want to add button on my activity_main.xml but program read file.map and when i add button it didn't show. how can i add button and show it on map ?

See in mapsforge-samples-android the layouts mapviewer.xml or rotatemapviewer.xml.

Essentially you can handle map view as any other Android view and place it in various layouts.

--
Emux

arra...@gmail.com

unread,
Mar 7, 2017, 5:08:00 AM3/7/17
to mapsforge-dev
when i add 
<org.mapsforge.map.android.view.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

on my main.xml it show rendering problems the classes could not be instantiated

Emux

unread,
Mar 7, 2017, 12:27:32 PM3/7/17
to mapsfo...@googlegroups.com
Are you sure all needed Mapsforge dependencies are in your classpath?

--
Emux

arra...@gmail.com

unread,
Mar 7, 2017, 6:18:52 PM3/7/17
to mapsforge-dev



i added library and build path to my project but it still same

Emux

unread,
Mar 8, 2017, 2:41:15 AM3/8/17
to mapsfo...@googlegroups.com
When you mentioned rendering problems I assumed running the app on a device or emulator.

What image shows is trying to draw the map view in the visual user interface builder of a developer IDE.
So that's an harmless issue only for the layout designer.
It does not prevent creating a layout or running the application and it does not mean that the classes are not visible for the code.

Is the application working?

--
Emux

arra...@gmail.com

unread,
Mar 8, 2017, 2:50:24 AM3/8/17
to mapsforge-dev
application run well but main.xml mentioned rendering problems 

arra...@gmail.com

unread,
Mar 8, 2017, 3:02:31 AM3/8/17
to mapsforge-dev

i think it doesn't matter if the app run well.
 

but how limit the map so there's no grey area appear on my app when i scroll  down/up


Emux

unread,
Mar 8, 2017, 3:06:12 AM3/8/17
to mapsfo...@googlegroups.com
On 08/03/2017 10:02 πμ, arra...@gmail.com wrote:

but how limit the map so there's no grey area appear on my app when i scroll  down/up


I don't know your code or layout implementation.

Please check or run mapsforge-samples-android to see how all that can work.

--
Emux

arra...@gmail.com

unread,
Mar 8, 2017, 3:33:35 AM3/8/17
to mapsforge-dev
i mean how can i limit the map by bounding box on my app. which class i should study on mapsforge-samples-android ?

Emux

unread,
Mar 8, 2017, 3:42:27 AM3/8/17
to mapsfo...@googlegroups.com
Do you want to limit the map view space on screen, like make it occupying part of the screen?
You can have a look at DualMapViewer example.

Or you want to limit map bounds while panning the map?
mapView.getModel().mapViewPosition.setMapLimit(BoundingBox);

--
Emux

arra...@gmail.com

unread,
Mar 8, 2017, 4:48:31 AM3/8/17
to mapsforge-dev
yes i want to limit the map  view space on screen. so, only my map appear. on screen and there's no blank space or grey space like picture that i send.

Emux

unread,
Mar 8, 2017, 4:51:22 AM3/8/17
to mapsfo...@googlegroups.com
On 08/03/2017 11:48 πμ, arra...@gmail.com wrote:
yes i want to limit the map  view space on screen. so, only my map appear. on screen and there's no blank space or grey space like picture that i send.

Then you need to play with regular Android layout rules for hosting properly the view, like we do here.

--
Emux

arra...@gmail.com

unread,
Mar 8, 2017, 5:03:59 AM3/8/17
to mapsforge-dev
what about limit map bounds? what should i do with 

mapView.getModel().mapViewPosition.setMapLimit(BoundingBox);

Emux

unread,
Mar 8, 2017, 5:12:01 AM3/8/17
to mapsfo...@googlegroups.com
You can pass a BoundingBox class with the coordinates you want the map pan to stop.

--
Emux

Emux

unread,
Mar 8, 2017, 5:16:57 AM3/8/17
to mapsfo...@googlegroups.com
I pushed some internal changes in Mapsforge.

Android MapView should not have issues now in IDE layout designers.

You'd need to use the latest snapshot build (see guide) for that.

(Don't forget to clean / rebuild for the changes to take effect)

--
Emux

arra...@gmail.com

unread,
Mar 8, 2017, 7:41:19 AM3/8/17
to mapsforge-dev
it still mentioned rendering probloms on my case

Emux

unread,
Mar 8, 2017, 7:45:33 AM3/8/17
to mapsfo...@googlegroups.com
Have you used Mapsforge SNAPSHOT builds?

And it's important to clean / rebuild the project.

Probably you have to force Gradle to check for latest snapshot, like mentioned in the guide.

BTW mapsforge-samples-android work fine in layout designer.

--
Emux

arra...@gmail.com

unread,
Mar 8, 2017, 7:48:30 AM3/8/17
to mapsforge-dev
 try to follow  guide but when i add "compile 'org.mapsforge:mapsforge-core:master-SNAPSHOT'" on my gradle.app and sync it mentioned "gradle project sync failed" .  

Emux

unread,
Mar 8, 2017, 7:51:43 AM3/8/17
to mapsfo...@googlegroups.com
Have you made the above steps in the guide?

Like adding the extra repository?

--
Emux

arra...@gmail.com

unread,
Mar 8, 2017, 7:55:43 AM3/8/17
to mapsforge-dev
can you give me explanation how to used Mapsforge SNAPSHOT builds ? 

arra...@gmail.com

unread,
Mar 8, 2017, 7:56:33 AM3/8/17
to mapsforge-dev
yes, i added extra repository on my gradle, i try to follow integration guide but still same

Emux

unread,
Mar 8, 2017, 7:58:19 AM3/8/17
to mapsfo...@googlegroups.com
Can you post here your build.gradle?

--
Emux

arra...@gmail.com

unread,
Mar 8, 2017, 8:06:35 AM3/8/17
to mapsforge-dev
apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "25.0.2"

defaultConfig {
applicationId "com.example.ismile05.maps"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:21.0.3'
compile files('libs/mapsforge-core-0.7.0.jar')
compile files('libs/mapsforge-map-android-0.7.0.jar')
compile files('libs/mapsforge-map-0.7.0.jar')
compile files('libs/mapsforge-themes-0.7.0.jar')
compile files('libs/mapsforge-map-reader-0.7.0.jar')
compile files('libs/androidsvg-1.2.2-beta-1.jar')
compile files('libs/mapsforge-map-android-extras-0.7.0.jar')
compile files('mapsforge-map-android-0.7.0.jar')
compile files('libs/vtm-0.7.0.jar')
compile files('libs/vtm-android-0.7.0.jar')
compile files('libs/vtm-android-0.7.0-natives-armeabi.jar')
compile files('libs/vtm-android-0.7.0-natives-armeabi-v7a.jar')
compile files('libs/vtm-android-0.7.0-natives-x86.jar')
compile files('libs/mapsforge-map-android-master-20170308.105247-91.jar')
}

arra...@gmail.com

unread,
Mar 8, 2017, 8:08:49 AM3/8/17
to mapsforge-dev
where should i put SNAPSHOT builds on my gradle?

Emux

unread,
Mar 8, 2017, 8:15:13 AM3/8/17
to mapsfo...@googlegroups.com
- Where is the extra repository defined?

- Better not mix Mapsforge and VTM together, they're two different frameworks

- One declaration per library is needed, e.g. there are 3 map-android jars

- To use snapshots you need to remove the jars and use the statements in the guide replacing [CURRENT-VERSION] with master-SNAPSHOT

--
Emux

Emux

unread,
Mar 8, 2017, 8:22:39 AM3/8/17
to mapsfo...@googlegroups.com
Could you try removing all jars in "libs" sub-folder and replacing the dependencies section with the following:


}

dependencies
{
    compile fileTree
(include: ['*.jar'], dir: 'libs')
    testCompile
'junit:junit:4.12'
    compile
'com.android.support:appcompat-v7:21.0.3'


    compile
'org.mapsforge:mapsforge-core:master-SNAPSHOT'
    compile
'org.mapsforge:mapsforge-map:master-SNAPSHOT'
    compile
'org.mapsforge:mapsforge-map-reader:master-SNAPSHOT'
    compile
'org.mapsforge:mapsforge-themes:master-SNAPSHOT'
    compile
'net.sf.kxml:kxml2:2.3.0'

    compile
'org.mapsforge:mapsforge-map-android:master-SNAPSHOT'
    compile
'com.caverock:androidsvg:1.2.2-beta-1'
}

--
Emux

arra...@gmail.com

unread,
Mar 9, 2017, 4:15:33 AM3/9/17
to mapsforge-dev
thank you very much emux!   so, we don't use jars in libs folder ?

Emux

unread,
Mar 9, 2017, 4:21:20 AM3/9/17
to mapsfo...@googlegroups.com
Usually it's more convenient to avoid jars and it makes app maintenance far more easier, just need to change string versions instead of replacing files.

So if going that way you can empty the libs folder completely.

--
Emux

arra...@gmail.com

unread,
Mar 9, 2017, 4:52:56 AM3/9/17
to mapsforge-dev
hmm thank you for your exlpanation. 
I'm developing a route search application using search algorithms such as greedy or Djikstra. Can I apply the algorithm to application?

Emux

unread,
Mar 9, 2017, 4:54:53 AM3/9/17
to mapsfo...@googlegroups.com
What do you mean?

Using Mapsforge map files for routing is not possible.
You'd need a routing library like GraphHopper.

--
Emux

arra...@gmail.com

unread,
Mar 9, 2017, 5:03:47 AM3/9/17
to mapsforge-dev
i mean, i want to build map and navigation application. 

arra...@gmail.com

unread,
Mar 14, 2017, 1:23:28 AM3/14/17
to mapsforge-dev
so, can we integrate with graphhoper for routing ?

Emux

unread,
Mar 14, 2017, 4:30:58 AM3/14/17
to mapsfo...@googlegroups.com
On 14/03/2017 07:23 πμ, arra...@gmail.com wrote:
so, can we integrate with graphhoper for routing ?

Certainly, you can check GraphHopper Android sample using Mapsforge for map view and overlay the route.

--
Emux
Message has been deleted
Message has been deleted

Emux

unread,
Mar 20, 2017, 9:07:41 AM3/20/17
to mapsfo...@googlegroups.com
For GraphHopper specific questions you could ask in its forum providing also more details for any issue, like the logcat with exceptions, etc.

--
Emux

arra...@gmail.com

unread,
Apr 3, 2017, 4:52:53 AM4/3/17
to mapsforge-dev
Hi Emux, how can i remove markers from layer?

Emux

unread,
Apr 3, 2017, 4:57:16 AM4/3/17
to mapsfo...@googlegroups.com
You can see the various methods of Layers class, like:

mapView.getLayerManager().getLayers().remove ...

--
Emux

arra...@gmail.com

unread,
Apr 3, 2017, 5:31:26 AM4/3/17
to mapsforge-dev
can you please give me an example or show me Layers class? 

Emux

unread,
Apr 3, 2017, 5:39:30 AM4/3/17
to mapsfo...@googlegroups.com
Layers class can be seen in repository here.

Examples of overlays are many in mapsforge-samples-android (which is recommended to study), like OverlayMapViewer or LongPressAction.

--
Emux

arra...@gmail.com

unread,
Apr 3, 2017, 8:13:34 AM4/3/17
to mapsforge-dev
i'm sorry but i realy don't understand how to use it.

i have code to add marker : 

Marker markerHydrant = Utils.createMarker(this, R.drawable.marker_hydrant,new LatLong(cn.getLatitude(),cn.getLongitude()));
layers.add(markerHydrant);

and this code on onStart()
LocationMarker(mapView.getLayerManager().getLayers());

now, i want to remove these marker.

Emux

unread,
Apr 3, 2017, 8:16:36 AM4/3/17
to mapsfo...@googlegroups.com
You can use layers.remove(markerHydrant);

--
Emux

arra...@gmail.com

unread,
Apr 6, 2017, 3:15:17 AM4/6/17
to mapsforge-dev
hi emux, i trying to draw a line on my map. but when i add other line, its connect to the first one. i want to make it separate. so there's is 2 diferent line


Emux

unread,
Apr 6, 2017, 3:17:52 AM4/6/17
to mapsfo...@googlegroups.com
If you want to overlay separate lines why don't you use different Polyline layers, each with its own set of coordinates.

--
Emux

arra...@gmail.com

unread,
Apr 6, 2017, 3:29:03 AM4/6/17
to mapsforge-dev
okey, but if i want to use one polyline layer is it possible?

Emux

unread,
Apr 6, 2017, 3:34:24 AM4/6/17
to mapsfo...@googlegroups.com
No as current implementation of Polyline layer handles a single line, not a collection of lines.

That would need a new "Polylines" implementation, not a bad idea, if you want can create an issue for that.

--
Emux

arra...@gmail.com

unread,
Apr 7, 2017, 5:06:44 AM4/7/17
to mapsforge-dev
hi emux, i have some marker on my map. i want make it show different information using alertdialog for each marker. can you please give me a idea ?

Emux

unread,
Apr 7, 2017, 5:14:37 AM4/7/17
to mapsfo...@googlegroups.com
The OverlayMapViewer has the examples for how to use the marker tap and long press events.

You need the markers to include also any extra information, e.g. extend the Marker class and add title or description fields.

--
Emux

arra...@gmail.com

unread,
Apr 27, 2017, 11:44:10 PM4/27/17
to mapsforge-dev
hi emux, can i add traffic layer from google map api to my map?

Emux

unread,
Apr 28, 2017, 2:09:44 AM4/28/17
to mapsfo...@googlegroups.com
Adding custom raster tile sources in Mapsforge is easy, just need to create their implementation, e.g. OpenStreetMapMapnik.

But Google Maps terms of service mean to use their maps only inside their map library?

--
Emux

arra...@gmail.com

unread,
Apr 28, 2017, 8:57:40 AM4/28/17
to mapsforge-dev
sorry, can you explain what openstreetmapmapnik is ? 

Emux

unread,
Apr 28, 2017, 9:05:22 AM4/28/17
to mapsfo...@googlegroups.com
It's a class defining the properties of an online bitmap tile source.

In the specific example the OpenStreetMap "Standard" bitmap layer.

Can be used with Mapsforge as seen in DownloadLayerViewer example in mapsforge-samples-android.

Better don't be confused with it, if you need to define custom tile sources, an easier way can be seen in DownloadCustomLayerViewer example.

--
Emux

arra...@gmail.com

unread,
May 3, 2017, 10:28:14 PM5/3/17
to mapsforge-dev
so, using openstreetmapmapnink we can upload our costum layer and using it online ? 

Emux

unread,
May 4, 2017, 2:29:28 AM5/4/17
to mapsfo...@googlegroups.com
If you have a web server to host your custom made layer's tiles, you could write then a tile source (like in above links) and load it to Mapsforge.

--
Emux

arra...@gmail.com

unread,
May 9, 2017, 4:19:54 AM5/9/17
to mapsforge-dev
hi emux, how to get lat long when i tap the map or make a marker by tapping ?

Emux

unread,
May 9, 2017, 4:29:09 AM5/9/17
to mapsfo...@googlegroups.com
You can check OverlayMapViewer sample which has Mapsforge overlay examples with touch events too.

--
Emux

arra...@gmail.com

unread,
May 9, 2017, 4:43:01 AM5/9/17
to mapsforge-dev
I mean, when i click whereever on my map, i can get that lat long. not tapable marker

Emux

unread,
May 9, 2017, 5:15:59 AM5/9/17
to mapsfo...@googlegroups.com
Then you need to add the touch listener to the map tile layer, e.g. see LongPressAction example.

--
Emux

arra...@gmail.com

unread,
May 9, 2017, 6:31:34 AM5/9/17
to mapsforge-dev

i've add LongPreesAction code but why there's error on tileCache.get(0) ? when i try to running the app using tileCache it show exception java.lang.IllegalArgumentException: tileCache must not be null 

Emux

unread,
May 9, 2017, 6:35:33 AM5/9/17
to mapsfo...@googlegroups.com
It depends on how you use the Mapsforge library in your project (need to provide a cache).

You can either check how the above example works (study its code) or use your own implementation (like in getting started guide).

--
Emux

arra...@gmail.com

unread,
Jun 17, 2017, 2:17:48 AM6/17/17
to mapsforge-dev
hi emux, i want to make my marker look like moving following changes of LatLong. how can i make it look like moving ? 

Emux

unread,
Jun 17, 2017, 2:27:36 AM6/17/17
to mapsfo...@googlegroups.com, arra...@gmail.com
You can use Marker.setLatLong to change its coordinates and then do:

mapView.getLayerManager().redrawLayers();

--
Emux

arra...@gmail.com

unread,
Jul 11, 2017, 1:54:48 AM7/11/17
to mapsforge-dev, arra...@gmail.com
hi emux, how can i make my location marker move followed gps on mapsforge ? i use handler to handle coordinate changes. 

Emux

unread,
Jul 11, 2017, 1:59:57 AM7/11/17
to mapsfo...@googlegroups.com, arra...@gmail.com
You can check LocationOverlayMapViewer in Mapsforge samples, it enables the follow location mode.

--
Emux

arra...@gmail.com

unread,
Jul 11, 2017, 2:20:14 AM7/11/17
to mapsforge-dev, arra...@gmail.com
i've follow LocationOverlayMapView samples but my location marker not appear

Emux

unread,
Jul 11, 2017, 2:28:33 AM7/11/17
to mapsfo...@googlegroups.com, arra...@gmail.com
You need to study the sample and the used MyLocationOverlay, comparing with your implementation.

The sample works, so check how you have integrated it.

--
Emux
Reply all
Reply to author
Forward
0 new messages