Recommended way for handling multiple markers

75 views
Skip to first unread message

Carlos Cesar Caballero Díaz

unread,
Sep 27, 2017, 9:24:43 AM9/27/17
to mapsforge-dev
Hi, I am new with mapsforge, I have an offline maps application based on
osmdroid and I am migrating it to mapsforge.

The app uses multiple markers and they are included or removed from the
map using a search filter. With osmdrod I use an
ItemizedOverlayWithFocus for handling the markers independently from
other overlay layers (map, GPS position, etc...), so I can clean, remove
or add markers to the ItemizedOverlay list without taking care of the
other overlays.

With mapsforge there is a Marker object and I can include it to the
Layers list using add(), but is a little difficult to handle removing or
adding markers if they are in the same list as other overlays like map
or GPS position.

Is there a better way for handling my markers and only my markers?

Thank you so much.

Emux

unread,
Sep 27, 2017, 9:42:27 AM9/27/17
to mapsfo...@googlegroups.com
You can use a GroupLayer, to see its usage check PoiSearchViewer here.

An alternative always is to keep track of markers or even extend Marker and store some id, which can be used then for removal of specific markers.

--
Emux

Carlos Cesar Caballero Díaz

unread,
Sep 27, 2017, 11:30:22 AM9/27/17
to mapsfo...@googlegroups.com

Thanks Emux, I can easily handle multiple markers now, but this brings me to a new issue, if I use code like this inside a loop for assigning tap events to markers (MarkerBusiness is inheriting from Marker):

markersLayers.layers.add(new MarkerBusiness(b){
    @Override
    public boolean onTap(LatLong geoPoint, Point viewPosition, Point tapPoint) {
        Utils.hideKeyboard(activity);
        Log.e("AKAKAK", "onTap: "+this.business.getName() );
        detailsLayout.startDetaislLayout(this.business);
        return true;
    }
});

The event is triggered when I tap any place of the map with the last marker data. I seems that the marker event is applied to the whole GroupLayer

Greetings.

El 27/09/17 a las 09:42, Emux escribió:
--
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.
To post to this group, send email to mapsfo...@googlegroups.com.
Visit this group at MailScanner ha detectado un intento de fraude en la siguiente página web "groups.google.com". No confíe en esta página web: MailScanner ha detectado un intento de fraude en la siguiente p�gina web "groups.google.com". No conf�e en esta p�gina web: https://groups.google.com/group/mapsforge-dev.
To view this discussion on the web visit MailScanner ha detectado un intento de fraude en la siguiente página web "groups.google.com". No confíe en esta página web: MailScanner ha detectado un intento de fraude en la siguiente p�gina web "groups.google.com". No conf�e en esta p�gina web: https://groups.google.com/d/msgid/mapsforge-dev/78a84be7-ec10-27aa-bc35-71ac143fc077%40gmail.com.
For more options, visit MailScanner ha detectado un intento de fraude en la siguiente página web "groups.google.com". No confíe en esta página web: MailScanner ha detectado un intento de fraude en la siguiente p�gina web "groups.google.com". No conf�e en esta p�gina web: https://groups.google.com/d/optout.

Emux

unread,
Sep 27, 2017, 1:31:15 PM9/27/17
to mapsfo...@googlegroups.com
GroupLayer does not consume any touch events, it just propagates them to its children.
They're responsible, if each one consumes them or not (by returning true).

You can test the PoiSearchViewer sample to see them in action.

Also what do you log there?
Any marker details should be stored per marker, not globally, e.g. (this.business.getName()) if that's what you mean.

--
Emux

Carlos Cesar Caballero Díaz

unread,
Sep 29, 2017, 8:20:17 AM9/29/17
to mapsfo...@googlegroups.com

Emux, thanks again for your answer, if I use Circle as GroupLayer elements, there is no problem with the tap events, but if I use Marker, then for some reason the issue appears.

Greetings.

El 27/09/17 a las 13:31, Emux escribió:
--
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.
To post to this group, send email to mapsfo...@googlegroups.com.
Visit this group at MailScanner ha detectado un intento de fraude en la siguiente página web "groups.google.com". No confíe en esta página web: MailScanner ha detectado un intento de fraude en la siguiente p�gina web "groups.google.com". No conf�e en esta p�gina web: https://groups.google.com/group/mapsforge-dev.

Emux

unread,
Sep 29, 2017, 8:28:55 AM9/29/17
to mapsfo...@googlegroups.com
I updated the POI Search sample to use markers, can you have a look?

--
Emux

Carlos Cesar Caballero Díaz

unread,
Sep 29, 2017, 10:45:59 AM9/29/17
to mapsfo...@googlegroups.com
Thank you so much Emux, problem solved, I was ignoring the "if (contains(layerXY, tapXY))" condition and that was causing the weird tap event behavior.

Greetings.

El 29/09/17 a las 08:28, Emux escribió:
I updated the POI Search sample to use markers, can you have a look?

--
Emux
--
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.
To post to this group, send email to mapsfo...@googlegroups.com.
Visit this group at MailScanner ha detectado un intento de fraude en la siguiente página web "groups.google.com". No confíe en esta página web: MailScanner ha detectado un intento de fraude en la siguiente p�gina web "groups.google.com". No conf�e en esta p�gina web: https://groups.google.com/group/mapsforge-dev.
Reply all
Reply to author
Forward
0 new messages