I am using marker view in order to display marker.
My code:
View customView = LayoutInflater.from(activity).inflate(R.layout.dialog_obstacle_with_markers, null);
customView.setLayoutParams(new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
ImageView iv_marker = customView.findViewById(R.id.iv_marker);
iv_marker.setTag(reportItemArrayList.get(i).getReportId());
ImageView iv_marker_white = customView.findViewById(R.id.iv_marker_white);
FrameLayout fl_category = customView.findViewById(R.id.fl_category);
ImageView iv_obstacle = customView.findViewById(R.id.iv_obstacle);
TextView tv_obstacle = customView.findViewById(R.id.tv_obstacle);
int[] rgbValue = Utils.getRGBFromHex(reportItemArrayList.get(i).getColor());
iv_marker.setColorFilter(Color.rgb(rgbValue[0], rgbValue[1], rgbValue[2]));
Glide.with(activity)
.load(reportItemArrayList.get(i).getFilename())
.apply(new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.mipmap.ic_obstacle_place_holder)
.error(R.mipmap.ic_obstacle_place_holder))
.into(iv_obstacle);
tv_obstacle.setText(reportItemArrayList.get(i).getCategoryName());
MarkerView markerView = new MarkerView(new LatLng(Double.parseDouble(reportItemArrayList.get(i).getLat()), Double.parseDouble(reportItemArrayList.get(i).getLng())), customView);
markerViewManager.addMarker(markerView);
Here I have multiple same location markers available and I am able to see only first location marker and other marker are behind first marker due to same location.
Now I want to handle click event of other marker behind first marker.
Currently I am getting only first location marker click due to same location.
But I want all click events behind first marker.
Please help me with this.
you can not handle the click event of same location markers like this.
the markers should have different locations to handle them.
Related
I need some help to improve the performance of my algorithm, I'm struggling for days and can't find a good solution.
Goal: My app need to show a marker for each airport in the world (~1k markers), and each marker must show the airport name.
What I did: For the marker, I created an RelativeLayout with the Icon and a TextView to populate the name of aiport.
Also, I wrote a class "AirportCluster" extending DefaultClusterRenderer and inside the overrode method onBeforeClusterItemRendered I just cast the layout to Bitmap so it can be rendered on the map
#Override
protected void onBeforeClusterItemRendered(AirportItem airportItem, MarkerOptions markerOptions) {
RelativeLayout customLayoutMarker = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.custom_airport_marker,null);
String tAirportName = airportItem.getAirport().getAirportName().toLowerCase();
tAirportName = Character.toUpperCase(tAirportName.charAt(0)) + tAirportName.substring(1);
TextView textLabelAirportMarker = (TextView) customLayoutMarker.findViewById(R.id.label_text_airport_marker);
textLabelAirportMarker.setText(tAirportName);
customLayoutMarker.setDrawingCacheEnabled(true);
customLayoutMarker.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
customLayoutMarker.layout(0,0, customLayoutMarker.getMeasuredWidth(), customLayoutMarker.getMeasuredHeight());
customLayoutMarker.buildDrawingCache(true);
Bitmap flagBitmap;
if ( mMemoryCache.get(tAirportName) == null){
flagBitmap = Bitmap.createBitmap(customLayoutMarker.getDrawingCache());
mMemoryCache.put(tAirportName,flagBitmap);
}else{
flagBitmap = mMemoryCache.get(tAirportName);
}
BitmapDescriptor markerAirportWithText = BitmapDescriptorFactory.fromBitmap(flagBitmap);
markerOptions.icon(markerAirportWithText);
//markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.airport_marker));
}
As we can see in the code, I'm trying to cache it on the memory as well, but this is not working that good.
All the markers are being added on the method onMapReady inside a loop for each airport in the list
for (Airport temp : fixedAirports) {
LatLng latLng = new LatLng(temp.getCityLat(), temp.getCityLng());
// create marker
MarkerOptions markerOptions = new MarkerOptions().position(latLng).title("Marker in" + temp.getCityName());
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.airport_marker));
AirportItem offsetItem = new AirportItem(temp.getCityLat(), temp.getCityLng());
offsetItem.setAirport(temp);
mClusterManager.addItem(offsetItem);
}
Issue: I also have a custom image for clustered airports, and when i try to zoom in/out sometimes it take to much to the clustered icon dismiss and show the marker item for an airport, sometimes the icon of the item even overlaps the clustered one, just like on the images below.
What I have to do to these animations (changing from clustered icon from single markers) be more fast and smooth??
Prepare BitmapDescriptors first in background (i.e. Coroutines viewModelScope or another thread or asynctask or Rxjava), then load them to ui. Dont draw anything inside your ClusterRenderer class. Doing so helped me a bit.
I am using Mapbox android sdk for my map application, i want to use pointer icon('myIcon' in this case) which always points in the direction where user is moving.
I here is my code :
public void addMarker(MapboxMap mapboxmap) {
// marker view options : setting location and icon
MarkerViewOptions options = new MarkerViewOptions()
.position(latLng)
.anchor(0.5f, 0.5f)
.icon(myIcon);
MarkerView view = options.getMarker();
// added marker on map
mapboxMap.addMarker(options);
}
With marker views we don't expose a way to do this, and your only option is to adjust the marker rotation when the camera is rotated. A better solution would be to use runtime styling and a symbol layer. An example of this can be found in our demo app. To ensure that the marker always points in the correct direction you can use the icon-rotation-alignment property and set it to map. Hope this helps!
Setting rotation on location update {like setRotation(angle_you_want_to_set)} worked of me.
Example :
public void addMarker(MapboxMap mapboxmap, float angle) {
// marker view options : setting location and icon
MarkerViewOptions options = new MarkerViewOptions()
.position(latLng)
.anchor(0.5f, 0.5f)
//set angle of ration for icon
.setRotation(angle)
.icon(myIcon);
MarkerView view = options.getMarker();
// added marker on map
mapboxMap.addMarker(options);
}
I have made a custom marker,it comes perfectly when map is loaded,but my problem is when i zoom in or out the map,marker changes its position and also when i click on marker info window comes on another postition(not on its top),My code is as below,I cant find solution or idea what i have made wrong,Please save me.
code
private void plotMarkers(ArrayList<MyMarker> markers) {
if (markers.size() > 0) {
for (MyMarker myMarker : markers) {
System.out.println("================rounded bitmaps==========="
+ roundedBitmaps.toString());
// Create user marker with custom icon and other options
MarkerOptions markerOption = new MarkerOptions()
.position(new LatLng(myMarker.getmLatitude(), myMarker
.getmLongitude()));
markerOption.icon(BitmapDescriptorFactory.fromBitmap(myMarker
.getImgURL()));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(myMarker.getmLatitude(), myMarker
.getmLongitude())).zoom(12).build();
mMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
Marker currentMarker = mMap.addMarker(markerOption);
mMarkersHashMap.put(currentMarker, myMarker);
mMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter());
}
}
}
Custom Markers work in a different way as the standard markers. The problem you are facing is a known issue, The best way to deal with this are as follows:
Make sure that the image for the custom marker is symmetrical and id perfectly aligned to the anchor.
The info window should also be similarly aligned symmetrically in the center of the marker, else it will look ugly. Please note that the Custom marker icons often require a different anchor. For the info window, use a custom info window layout (with a custom background) to align it correctly to the marker.
i am using google map V2 in android, user can only view the map all other zooming spaning is set to diabled. Position of marker update after some intervals, now i want when ever the position of marker goes out of view bound the marker get centred as well as the map. so the user just see the current marker postion.
Use This:
LatLngBounds.Builder bld = new LatLngBounds.Builder();
bld.include(new LatLng(your latitude, your longitude));
LatLngBounds latLngBounds = bld.build();
yourMap.moveCamera(CameraUpdateFactory.newLatLngBounds(
latLngBounds, 50));
I think I have the same issue with the post on this link
Different markers show same infowindow content android google map v2
I am currently developing an app that integrates Google Maps v2 to allow users to take picture and automatically plotting a marker on the map.
I have a working InfoWindowAdapter but it seems that when I set a Bitmap as you can see below:
ImageView ivIcon = ((ImageView)myContentsView.findViewById(R.id.iconImg));
ivIcon.setImageBitmap(getResizedBitmap(myBitmap.getBp(),100,100));
When taking multiple pictures using my camera (which means it will have respective markers plotted on the map), the markers all share the same image, which is the latest image taken from the camera. I thought creating a Class by checking for difference in Bitmap object name would solve the problem but it did not.
It seems that when applying:
myMap.setInfoWindowAdapter(new MyInfoWindowAdapter());
it applies to all markers.
How do I go around doing it that each marker would have its own custom info window adapter?
Thanks!
======================================== EDIT =================================
I have an application that will allow users to take pictures which will also plot a marker on the map of the location of image capture. The marker will have a custom InfoWindow. I tried the solution but they are vague to me.
Do you mind explaining what did you do to your code such that doing:
googleMap.setInfoWindowAdapter(new InfoWindowAdapter());
will not affect all the markers on the map?
My current code for the CustomInfoBox is as follows:
class MyInfoWindowAdapter implements InfoWindowAdapter{
private final View myContentsView;
MyInfoWindowAdapter(){
myContentsView = getLayoutInflater().inflate(R.layout.custom_info_window, null);
}
#Override
public View getInfoContents(Marker marker) {
//TextView tvTitle = ((TextView)myContentsView.findViewById(R.id.title));
// tvTitle.setText(marker.getTitle());
TextView tvSnippet = ((TextView)myContentsView.findViewById(R.id.snippet));
tvSnippet.setText(marker.getSnippet());
ImageView ivIcon = ((ImageView)myContentsView.findViewById(R.id.badge));
ivIcon.setImageBitmap(getResizedBitmap(myBitmap.getBp(),100,100));
System.out.println("Custom Info Window: " + myBitmap.getBp());
return myContentsView;
}
#Override
public View getInfoWindow(Marker marker) {
// TODO Auto-generated method stub
return null;
}
}
When I call googleMap.setInfoWindowAdapter(MyInfoWindowAdapter);, all markers have the same layout and thus same picture (last picture taken by user!) which is not something that I want.
Any help will be much appreciated! thanks