Is it possible to show/hide Markers in Android Google maps api v2?
Solution 1
Try this way.
Marker restuarantMarkers = gMap.addMarker(new MarkerOptions()
.position(latlng)
.title("MyPlace").icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_pin)).draggable(true));
On Click Event
restuarantMarkers.setVisible(false);
This way can do using loop..
Let me know if it works for you.
Solution 2
You can use dialog if you want to filter your locations.
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog);
Button bt_ok = (Button) dialog.findViewById(R.id.button1);
final CheckBox cb1 = (CheckBox) dialog.findViewById(R.id.checkBox1);
final CheckBox cb2 = (CheckBox) dialog.findViewById(R.id.checkBox2);
dialog.setTitle("Category");
bt_ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mMap.clear();
if (cb1.isChecked()){
mMap.addMarker(new MarkerOptions().position(new LatLng(44.109798, 15.242270)).title("Pin").icon(BitmapDescriptorFactory.fromResource(R.drawable.museum)));
}
if (cb2.isChecked()){
mMap.addMarker(new MarkerOptions().position(new LatLng(44.209798, 15.392270)).title("Pin 2").icon(BitmapDescriptorFactory.fromResource(R.drawable.restaurants)));
}
dialog.dismiss();
}
});
dialog.show();
Rami
I am a Data Scientist with experience in Machine Learning, Big Data Analytics and Computer Vision. I am currently working on advanced Machine Learning technologies for Mobile Operators Subscribers Analytics to optimise advertisement, recommendation and costumer care services. Co-founder and organiser of the Lifelogging@Dublin Meetup group, I am an active long-term Lifelogger with particular interest in human behaviour tracking and analytics.
Updated on July 16, 2020Comments
-
Rami almost 4 years
I would like (in my Android app using Google maps api v2) to hide or show markers on my GoogleMap object according to a category, just like in the google maps web api, for example:
I have a GoogleMap with 50 Markers, 20 of them represent restaurants, 20 them represent bus stops, and 10 are cinemas.
Is it possible on Android google maps api v2 to do filtering on these markers, by hiding all the restaurant markers if we un-tick a checkbox for example?
I would like to do something like that but on my Android device using google maps api v2: http://www.geocodezip.com/v3_MW_example_categories.html
Sorry for the basic question but I am a beginner.
-
Rachel Gallen over 11 yearsi'm not sure about the check box thing but this is code to add and remove markers
-
Rachel Gallen over 11 yearsYou would have to find the latitude and longitude using geocoding. There is a Geocoder class in Android.
-
Rami over 11 yearsHi Rachel, the code is bout adding or deleting markers according to the latitude and longitude, I do not need this. I would like to hide or show according a category or description or title or anything like this.
-
Rachel Gallen over 11 years
-
Rami over 11 yearsThank you again Rachel but the links that you posted is not for Android, is for a web application :) I edited my question by putting your second link. I would like to do that using Android google maps not in a web page :)
-
Rachel Gallen over 11 yearscould you convert it somehow?
-
Rami over 11 yearsThere is no direct conversion, that is why I am asking.
-
Rachel Gallen over 11 yearssee this link it may help you can set visible to false developers.google.com/maps/documentation/android/marker
-
Rami about 11 yearsThank you for the hint Mitesh, I managed to do it based on your answer. thank you :)
-
Wikki over 9 years@droid_dev: is it possible to store marker reference in arraylist or hashmap and then show hide marker by arry or hasmap. Means show all markers of contained in one hashmap
-
moDev over 9 years@Wikki Yes its possible
-
ltvie over 9 years@droid_dev : I'm looking for a tutorial on show / hide the specific markers in google maps v2 using hashmap? where I get the link..thanks
-
Neo42 over 5 yearsWhat does this even do?