Android Studio Polyline gradient Not working - android

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

Related

Android WMS: Problems generating "bbox" using the OSMDroid library

I have a problem when consulting a WMS using the OSMDroid library, the problem lies in an erroneous generation of the bbox. For example, this is a good url with a correct bbox:
https://www.ign.es/wms-inspire/pnoa-ma?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image%2Fjpeg&TRANSPARENT=true&LAYERS=OI.OrthoimageCoverage&srsname=EPSG%3A25829&TILED=true&WIDTH=256&HEIGHT=256&SRS=EPSG%3A25829&BBOX=580836.6437384554%2C4745328.435582805%2C581278.1741512696%2C4745769.96599562
However, using the OSMDroid library, It shows me a white square for the badly generated bboxes:
https://www.ign.es/wms-inspire/pnoa-ma?SERVICE=WMS&request=GetMap&width=256&height=256&version=1.1.1&layers=OI.OrthoimageCoverage&bbox=580836.6437384554%2C4745328.435582805%2C581278.1741512696%2C4745769.96599562&srs=EPSG:3857&format=image/png&transparent=true
What I tried is this code that generate a WMSTileSource, which is set on the map:
val tileSource = WMSTileSource("OI.OrthoimageCoverage", arrayOf("https://www.ign.es/wms-inspire/pnoa-ma?SERVICE=WMS&"), "OI.OrthoimageCoverage","1.1.1", "EPSG:3857", null, 256)
binding.map.setTileSource(tileSource)
This error is due to the bbox, is there any configuration that should be done in the bbox or some way to handle it in a more customized way?
This should give me a map painted like this:
However, when I compile, it just shows me a blank map:

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

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

Categories

Resources