I added a marker to the map using the following method and also saved a marker record
public static void showallLocations()
{
ArrayList<LinkedHashMap<String, String>> listshow=latLngStoragepreference.getLatlng();
markerlist=new ArrayList<Marker>();
if(listshow.size()>0)
{
for(int i=0;i<listshow.size();i++)
{
LinkedHashMap<String, String> Linkedhashmap=listshow.get(i);
Set mapSet = (Set) Linkedhashmap.entrySet();
Iterator mapIterator = mapSet.iterator();
Map.Entry mapEntry = (Map.Entry) mapIterator.next();
String keyValue = (String) mapEntry.getKey();
String value = (String) mapEntry.getValue();
String[] parts=value.split("#");
String Latitude=parts[0];
String Longitude=parts[1];
Double Latitudeconverted=Double.parseDouble(Latitude);
Double Longitudeconverted=Double.parseDouble(Longitude);
System.out.println(Latitudeconverted+""+Longitudeconverted);
LatLng latLngs=new LatLng(Latitudeconverted, Longitudeconverted);
Marker marker=map.addMarker(new MarkerOptions()
.position(
latLngs)
.title(keyValue)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_navigate_to)));
markerlist.add(marker);
}
}
}
in the user base adapter, I tried to remove the marker, but it marker.remove()doesn’t work
holder.btnDeletelocation.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Marker marker= MainActivity.markerlist.get(position);
Log.d("MARKERlist before Remove", MainActivity.markerlist.toString());
Log.d("MARKER Title",marker.getTitle());
marker.remove();
marker.setVisible(false);
Log.d("MARKERlist after Remove", MainActivity.markerlist.toString());
notifyDataSetChanged();
}
});
Please help if someone went through the same thing. thanks in advance
source
share