Osmdroid Workaround For The Classic Markers Overlapping
Solution 1:
I don't know if this will help you.
I needed to create a CustomInfoBubble
for my project. What I did was, to extend the InfoWindow
default class, and pass to it my custom bubble layout. Something like this:
http://mobiledevstories.wordpress.com/2014/03/01/osmdroid-bonus-pack-markers-with-clickable-infowindows/
My Java class MapCustomInfoBubble
looks like this:
publicclassMapCustomInfoBubbleextendsInfoWindow {
publicMapCustomInfoBubble(MapView mapView) {
super(R.layout.map_infobubble_black, mapView);//my custom layout and my mapView
}
@OverridepublicvoidonClose() {
//by default, do nothing
}
@OverridepublicvoidonOpen(Object item) {
Markermarker= (Marker)item; //the marker on which you click to open the bubble Stringtitle= marker.getTitle();
if (title == null)
title = "";
ButtonmoreInfo= (Button)mView.findViewById(R.id.bubble_moreinfo);//the button that I have in my XML;
moreInfo.setText(title);
moreInfo.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View v) {
gotoMoreInfoWindow();//custom method; starts another activity
}
});
}
}
In my XML file, I have:
<?xml version="1.0" encoding="UTF-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:background="@drawable/map_infobubble_black" ><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal" ><TextViewandroid:id="@+id/bubble_title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="#FFFFFF"android:maxEms="17"android:layout_gravity="left"android:layout_weight="1"android:text="Title" /><Buttonandroid:id="@+id/bubble_moreinfo"android:background="@drawable/map_btn_moreinfo"android:visibility="visible"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:layout_weight="0" /></LinearLayout></LinearLayout>
Somewhere else in my code, I then use:
Marker wp = new Marker(mapView);
wp.setPosition(new GeoPoint(mylocation.getMyLocation()));
wp.setTitle(editTextName.getText().toString());
wp.setInfoWindow(new MapCustomInfoBubble(mapView));
mapView.getOverlays().add(wp);
mapView.invalidate();
In my code, I set the text on the button
with the Marker
's title.
The Marker
is the item on which I click. If you want to put info about more markers in the same InfoWindow
(inside a ListView
), I think you would need to know in advance what the info will be.
I believe that, You can put whatever code you want inside onOpen()
, however, I am not so sure if it's a good practice. You could try creating a custom Constructor
and put your logic there. It should work.
You need to pass the Resource Id
(layout) and mapView
to the super constructor, so it returns a valid mView
object.
Post a Comment for "Osmdroid Workaround For The Classic Markers Overlapping"