How can I make the circles clickable on MapBox? - android

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

Related

Android mapbox v10 - dynamically change the source url

We have a usual source url of something like https://my-source/{x}/{y}/{z}. When the user selects filtering options, we'd like to add these params to the url as something like https://my-source/{x}/{y}/{z}?my-param=true and instantly update the map.
Is this possible to achieve in mapbox?
Turns out this is relatively simple! If a little difficult to find, the code below will update the tile url dynamically:
val source = style.getSourceAs<VectorSource>(CHARGE_POINT_SOURCE_ID)
source?.tiles(listOf(newSourceUrl))

Adding dynamic markers on mapbox does not work with SymbolLayer

I am currently developing android map using mapbox sdk, and I want to add multiple markers when user click on one button. and I type below in my onStyleLoaded but it's not showing anything
List<Feature> symbolLayerIconFeatureList = new ArrayList<>();
symbolLayerIconFeatureList.add(Feature.fromGeometry(
Point.fromLngLat(31.995560, 34.767070)));
symbolLayerIconFeatureList.add(Feature.fromGeometry(
Point.fromLngLat(31.995979, 34.744110)));
symbolLayerIconFeatureList.add(Feature.fromGeometry(
Point.fromLngLat(31.995010, 34.767380)));
style.addImage("charge-icon-id", BitmapFactory.decodeResource(
MapboxNavigationActivity.this.getResources(), R.drawable.map_marker_dark));
style.addSource(new GeoJsonSource("charge-source-id",
FeatureCollection.fromFeatures(symbolLayerIconFeatureList)));
SymbolLayer destinationSymbolLayer = new SymbolLayer("charge-layer-id", "charge-source-id");
destinationSymbolLayer.withProperties(iconImage("charge-icon-id"),
iconAllowOverlap(true),
iconIgnorePlacement(true)
);
style.addLayer(destinationSymbolLayer);
May I ask what are the problem?
It's a bit tough to say without some more context/information, but I'm guessing that the issue is related to the order in which you're adding the source, layer, and image. Take a look at this example: https://docs.mapbox.com/android/maps/examples/marker-symbol-layer/
You'll want to add the image, source, and layer before the style is loaded. You can then make additional adjustments/add data when the style is loaded using the onStyleLoaded listener.
Disclaimer: I work at Mapbox.

Android: Markers is added to mapbox with super delay

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.

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...

How to Draw Route Received From MapQuestApi in nutiteq Map?

i have some problems creating route directionns on the nutiteq map from MapQuestApi, i Know how to Receive the Information needed
#Override
public void onSuccess(RouteResponse routeResponse) {
clearButton.setVisibility(View.VISIBLE);
if(showItineraryButton.getVisibility()==View.GONE &&
showMapButton.getVisibility()==View.GONE){
showItineraryButton.setVisibility(View.VISIBLE);
}
createRouteButton.setEnabled(true);
}
});
but i dont know how to use them to create route lines on them nutiteq map, and appearantly its demo sample doesnt say any thing, it has a RouteActivity Interface which does not exists any where in the Sample Codes, if any one has done this , can some one please show me how can i "draw" the route points using received information ? i would really appreciate
The RouteActivity is in separate project AdvancedLayers.
From MapQuestRouteActivity.java in AdvancedMap3D project you can find method public void routeResult(Route route) which is called from MapQuestDirections.java (source is also in AdvancedLayers). The MapQuestDirections has already parsed routing result and created a line (which is part of the Route) which can be added to the map.

Categories

Resources