Suppose i have 100 markers on the map what i want is when i apply GoogleMap.clear(); to clear the map it clear all the other markers on the map except 2 markers and 1 polyline between them a path.
say
marker1 = GoogleMap .addMarker(new MarkerOptions().position(latLng1).title(A));
marker2 = GoogleMap .addMarker(new MarkerOptions().position(latLng2).title(B));
line = GoogleMap.addPolyline(options1);
I don't want to clear these three. I want this so user don't have to experience a blink.
There is no way to clear everything except some things. However, you can keep a reference to any markers that you want to clear and loop over them.
ArrayList<Marker> markersToClear = new ArrayList<Marker>();
marker1 = GoogleMap.addMarker(new MarkerOptions().position(latLng1).title(A));
marker2 = GoogleMap.addMarker(new MarkerOptions().position(latLng2).title(B));
marker3 = GoogleMap.addMarker(new MarkerOptions().position(latLng3).title(C));
markersToClear.add(marker2);
markersToClear.add(marker3);
for (Marker marker : markersToClear) {
marker.remove();
}
markersToClear.clear();
// marker1 left on map
Related
I am adding google map marker with 1000 marker in small boundery box, while moving map arround, app frezzing, didn't know why,
Also i have tried marker cluster . but client has refuesed it, he need all marker to be shown on map, as marker is mandetory to show to user...!
is there any way to do so with better preformance
i figure that may i zoom in to custom point and show marker only with boundry box map, and while user move map he remove marker around and put new marker
but this will come on looping in array with 1000 element in it, and this is n't better solution, any one know how to do so !!!?
for (int i = 0; i < stopDetailsModelResponses.size(); i++) {
mapHelper.setMarkerPinWithLayoutToImage(
stopDetailsModelResponses.get(i).getStopDetailsLat(),
stopDetailsModelResponses.get(i).getStopDetailsLong(),
stopDetailsModelResponses.get(i).getStopDetailsName(),
String.valueOf(stopDetailsModelResponses.get(i).getStopDetailsId()),
stopDetailsModelResponses.get(i).getStopDetailsLogoUrl(),
stopDetailsModelResponses.get(i).getStopDetailsType(),
markerOptions, googleMap, getContext()
);
}
googleMap.setOnMarkerClickListener(onMarkerClickListener);
this for looping inside list to set element to map marker
and this for adding marker to map
try {
markerOptions = new MarkerOptions()
.position(new LatLng(lat, longitude))
.title(locationName)
.draggable(false);
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(defineLayoutOfPin(context, imageType, locationId)));
googleMap.addMarker(markerOptions);
} catch (Exception e) {
Log.e("setMarkerWithImage: ", e.getMessage());
}
In onMapReady I am defining a few markers
First I declare the marker and his icon that is common for all markers and then each marker with it's own attributes. The problem is that when I declare the marker I cannot declare it as Marker beerMarker = new Marker() options as it makes me cast the Marker into MarkerOptions. What I would like is to call the info window for every marker but I cant as the beerMarker.showInfoWindow() is not acceptable for MarkerOptions. What am I doing wrong and what are the alternatives?
MarkerOptions beerMarker = new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.beer_marker));
//Carciuma
LatLng carciuma = new LatLng(43.604892, 1.476562);
mMap.addMarker(beerMarker.position(carciuma).title("Carciuma"));
//Boca
LatLng boca = new LatLng(43.604496, 1.474924);
mMap.addMarker(beerMarker.position(boca).title("Boca"));
//Bar Acasa
LatLng barAcasa = new LatLng(43.604781, 1.474502);
mMap.addMarker(beerMarker.position(barAcasa).title("Bar Acasa"));
Here is the updated version of the marker that meens I have t have to add for every individual marker the same icon, no?
LatLng barAcasa = new LatLng(43.604781, 1.474502);
Marker beerMarkerAcasa = mMap.addMarker(new MarkerOptions()
.position(barAcasa)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.title("Bar Acasa"));
beerMarkerAcasa.showInfoWindow();
You can get this way Marker marker = mMap.addMarker(markeroption);
you can pass marker option for particulate marker in addMarker() method, they return marker instance which you can use.
googleMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
googleMap.addMarker(new MarkerOptions()
.position(
new LatLng(Float.parseFloat(latitude), Float
.parseFloat(longitude)))
.title("Marker").title(title));
**googleMap.addPolyline(new PolylineOptions()
.add(new LatLng( Double.parseDouble(latitude1), Double.parseDouble(longitude1)),
new LatLng( Double.parseDouble(latitude), Double.parseDouble(longitude)))
.width(5).color(Color.BLUE).geodesic(true));;**
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
cameraLatLng, 17));
So basically that's what I have done, but what that code does is it draws a line from a source to a destination. However, I do not want to draw a line, I just want to show route direction.
like this picture http://s7.postimg.org/dwdbkq6h7/Screenshot_2015_04_14_20_40_58.png
You can use the Google Direction API to find a route between two points.
I would like to know how I can create a Marker but not to show on the map, I'm saving the Markers in an array but it is showing me on the map, this is my code
if (c4!= null ) {
if (c4.moveToFirst()) {
do {
LatLng posicion = new LatLng(
Double.parseDouble(c4.getString(0)),
Double.parseDouble(c4.getString(1)));
punto = googleMap.addMarker(new MarkerOptions() .position(posicion)
.title(c4.getString(2))
.snippet(year)
.anchor(0.5f, 0.5f));
mMarkers.add(punto);
}while (c4.moveToNext());
}
}
I've tried and used this
MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude));
but this does not work for me as I need to be type Marker.
Anyone know how could i save spots without paint on the map? thank you very much and sorry for my bad English :)
Try using:
punto = googleMap.addMarker(new MarkerOptions() .position(posicion)
.title(c4.getString(2))
.snippet(year)
.anchor(0.5f, 0.5f).visible(false));
instead of
punto = googleMap.addMarker(new MarkerOptions() .position(posicion)
.title(c4.getString(2))
.snippet(year)
.anchor(0.5f, 0.5f));
Notice the .visible(false) part.
For further info regarding the same refer: http://developer.android.com/reference/com/google/android/gms/maps/model/MarkerOptions.html
save the markers in this list
List<Marker> markers = new ArrayList<Marker>();
markers.add(marker); // here the marker is of google map
Then afterwords use Clear() on your google map so that the markers that got add should be deleted
EDIT=
Also you can separately remove a single marker by
marker.remove();
you can also try to save the latitude and longitude in array list and then later as you like it, show them through marker.
I connected map locations using Polyline API. It creates polyline properly.But sometimes unwanted polyline extended when zoom in and disappears on zoom out.
My code:
locations.clear();
for(int i=0;i<maplatitude.size();i++)
{
locations.add(new LatLng(maplatitude.get(i), maplongitude.get(i)));
}
PolylineOptions rectOptions = new PolylineOptions();
rectOptions.addAll(locations);
// Get back the mutable Polyline
Polyline polyline = mMap.addPolyline(rectOptions);
for(int i=0;i<maplatitude.size();i++)
{
//mMap.addMarker(new MarkerOptions().position(new LatLng(maplatitude.get(i), maplongitude.get(i))).title(name).snippet(mapdate.get(i)+"\n"+maptime.get(i)));
mMap.addMarker(new MarkerOptions().position(new LatLng(maplatitude.get(i), maplongitude.get(i))).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)).title(String.valueOf(i)));
}
I solved this: it's a bug from Google. We must filter some close points within 1 or 2 meters.
Polylines appearing on map where they shouldn't