Android: Markers is added to mapbox with super delay - android

I am using map box in my android application. After initializing map box I want to add marker when on longClick on map box so in order according official site I added markerview dependency to application gradle:
dependencies {
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-markerview-v7:0.2.0'
}
And then I implements MapboxMap.OnMapLongClickListener and override onMapLongClick.
When mapview is ready I enable enableLocationComponent and create markerViewManager and set map long click listener.
mapView.getMapAsync(mapboxMap -> {
this.mapboxMap = mapboxMap;
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
createCustomAnimationView();
moveTo(home_longitude, home_latitude, home_zoom);
enableLocationComponent();
markerViewManager = new MarkerViewManager(mapView, mapboxMap);
mapboxMap.addOnMapLongClickListener(this);
createCustomAnimationView();
});
});
Finally in onMapLongClick overrided method I make a imageview and add to markerViewManager.
#Override
public boolean onMapLongClick(#NonNull LatLng point) {
ImageView imageView = new ImageView(requireContext());
imageView.setLayoutParams(new RelativeLayout.LayoutParams(
(int) Measurement.convertDpToPixel(32, requireContext()),
(int) Measurement.convertDpToPixel(32, requireContext())));
imageView.setImageResource(R.drawable.location_ic);
MarkerView markerView = new MarkerView(new LatLng(point.getLatitude(), point.getLongitude()), imageView);
markerViewManager.addMarker(markerView);
return false;
}
When I run application and do long click on screen:
First problem: location_ic appear on the top and left of the screen and after a second or more, icon placed in right place
Other problem:
When I move map, those markers stay fixed and not moved with map but after a second or more then placed in right place.
I hope I had explained clearly but if you are not understanding I uploaded a small video !!!
My video

after a few days and googleing, I finally decided to use SymbolManager to add marker on mapbox:
just add :
dependencies {
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:0.5.0'
}
to app gradle and then Initialize the plugin on onMapReady like below:
symbolManager = new SymbolManager(mapView, mapboxMap,style);
symbolManager.setIconAllowOverlap(true);
symbolManager.setTextAllowOverlap(true);
and use :
symbolManager.create(new SymbolOptions()
.withLatLng(point)
.withIconImage(IMAGE_MARKER_DEFAULT));
for helping look this page and this.
I hope it can be helpful.

I'm currently working with markers in mapbox too. But they are referred as "Symbols" in the latest versions.
To use them add the mapbox android sdk dependency to your project (tutorial from mapbox here ) and follow the other tutorial to use the symbol layer ( link here ).
If you have all your markers as a GeoJSON file, you can also add to a custom map that you would style on the mapbox website and then use in your app. ( other informations here )
I hope this can help you, this is my first attempt to answer at someone.

Related

Android Studio Polyline gradient Not working

When I try to make a gradient polyline using StyleSpan(StrokeStyle.gradientBuilder(Color.RED,Color.GREEN).build()) but it will return only black color. Kindly share your guidance
I need to draw gradient route in map kindly share your knowledge
To enable the use of StyleSpan you have to initializate your map with latest render. If not, the legacy is set for default and that render doesn't include this option.
To do this at the begining of the onCreate fun add the following line:
MapsInitializer.initialize(applicationContext,Render.LATEST, this)
It is important to call it before any MapView, MapFragment, or SupportMapFragment has been created
You can also implement the following function to check which version are you using.
override fun onMapsSdkInitialized(renderer: MapsInitializer.Renderer) {
when (renderer) {
Renderer.LATEST -> Log.d("MapsDemo", "The latest version of the renderer is used.")
Renderer.LEGACY -> Log.d("MapsDemo", "The legacy version of the renderer is used.")
} }
More information about this is availabe https://developers.google.com/maps/documentation/android-sdk/renderer

How can I make the circles clickable on MapBox?

I am working with Mapbox to create a map application. I want to have some clickable circles on the map. I already got the circles on the map but i cant seem to make them clickable. I read about a circlemanager that I need to use but I cant get that to work.
I've already tried to make a Circlemanager as seen below.
CircleManager circleManager = new CircleManager(mapView, mapboxMap, style);
circleManager.addClickListener(circle -> Toast.makeText(container.getContext(),
String.format("Circle clicked %s", circle.getId()),
Toast.LENGTH_LONG).show());
I wrote that code so I can test if the application detects the click. But I don't get any feedback/errors.
You can have a look from GitHub repository might it work for you.
https://github.com/mapbox/mapbox-plugins-android/blob/master/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/CircleActivity.java

Polyline with infowindow in android app

In android map application, it shows tool-tip window for multiple route, the same way google map also shows that window. I was wondering whether that is a custom marker or a infoWindow over poly-line.
Does any body knows how to achieve this with android map-v2 integration?
Following image show my expectations to implement in android.
2020 Solution (Kotlin)
I wrote this little Kotlin extension function (simply add to your extension functions or anywhere in your code) to do exactly the job needed: It adds an info window half way on the polyline.
fun Polyline.addInfoWindow(map: GoogleMap, title: String, message: String) {
val pointsOnLine = this.points.size
val infoLatLng = this.points[(pointsOnLine / 2)]
val invisibleMarker =
BitmapDescriptorFactory.fromBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888))
val marker = map.addMarker(
MarkerOptions()
.position(infoLatLng)
.title(title)
.snippet(message)
.alpha(0f)
.icon(invisibleMarker)
.anchor(0f, 0f)
)
marker.showInfoWindow()
}
Use as follows:
polyline.addInfoWindow(map, "Title", "Message")
Example use:
polyline.addInfoWindow(map, route.distanceText, route.durationText)
In the Google Maps Android API it says that:
An info window displays text or images in a popup window above the map. Info windows are always anchored to a marker. Their default behavior is to display when the marker is tapped.
Therefore, you will either have to use another solution than just attaching an info window to the polyline. Maybe you can create an invisible marker at the location, the polyline has been clicked, on the fly which opens the info window.
In case someone is still looking for an answer, you can use bubble icons from the maps-utils library. It lets you create customized markers, that look just like infowindows. You can run a demo from here, but make sure you import is as a project when you run it: File->New->Import Project...

Disable infowindow when click cluster in mapV2

I have referred this https://developers.google.com/maps/documentation/android/utility/marker-clustering link to implement simple cluster in my application
Now I want to disable the cluster onclick
In my screen when I click 3 my info window is showing but I don't want to show infowindow; instead of that, I need to zoom the map.
I have tried
mClusterManager.onInfoWindowClick(null);
mClusterManager.setOnClusterClickListener(null);
mClusterManager.setOnClusterInfoWindowClickListener(null);
mClusterManager.setOnClusterItemClickListener(null);
mClusterManager.setOnClusterItemInfoWindowClickListener(null);
// render.setMarkersToCluster(false);
render.setOnClusterClickListener(null);
render.setOnClusterInfoWindowClickListener(null);
render.setOnClusterItemClickListener(null);
render.setOnClusterItemInfoWindowClickListener(null);
These tries are not at all working; please give me some idea of what to do.
So as we discuss above:
You can use hideInfoWindow() method
Set Renderer from cluster manager as following:
mClusterManager.setRenderer(myClusterRenderer);
Get the marker and hide it as following:
#Override
public void onClusterItemInfoWindowClick(final myPOI item) {
myClusterRenderer.getMarker(item).hideInfoWindow();
}

Android google maps marker disable navigation option

Im creating an app where users need to walk to a point on a map. But they need to find a route to the point by them selves.
Ive created a map with markers but by default if a user clicks on the marker a "start navigation" and "view in google maps" option is shown. Is it possible to disable these options ?
The options that are shown on marker click
This thing is called Map Toolbar. You can disable it by calling UiSettings.setMapToolbarEnabled(false):
GoogleMap map;
....... //init map
map.getUiSettings().setMapToolbarEnabled(false);
You can also define setMapToolbarEnabled() from the XML using the following property:
map:uiMapToolbar="false"
In kotlin you can do:
map.apply {
uiSettings.isMapToolbarEnabled = false
}
If anyone needs to do this in Google Maps v2, you set it in the map options instead of setting it on the map directly. So like this:
var mapOptions = new GoogleMapOptions().InvokeMapToolbarEnabled(false);

Categories

Resources