Juzmulti
Juzmulti

Reputation: 123

Markers not shown on styled MapView on Mapxbox Android

I need some help on Mapbox Android. I've drawn without problems a polyline and some custom markers on a default styled map, but, when I change the default style into a custom style, I can still see the polyline but markers are not drawn (neither custom or default markers).

Could anyone help me with this issue?

This is my code:

//Setting style
mapView.setStyleUrl(Constants.MAP_URL_GREEN);

//Adding polilyne
PolylineOptions options = new PolylineOptions();

for(double[] coordArray : route.getListCoords()) {
    options.add(new LatLng(coordArray[0], coordArray[1]));
 }
options.color(ContextCompat.getColor(getContext(), R.color.color_end_green));
options.width(5);

mapView.addPolyline(options);

//Adding markers
MarkerOptions currentMarker;
for(Point point : route.getListPoints()){
    currentMarker = getMarkerFromPoint(point);
    markers.add(mapView.addMarker(currentMarker));
}

Where getMarkerFromPoint is:

private MarkerOptions getMarkerFromPoint(Point point) {

    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(new LatLng(point.getLat(), point.getLng()));
    //markerOptions.icon(MapUtils.getPointIcon(point, getContext()));

    return markerOptions;
}

EDIT: I am using the MapBox Android SDK 3.2.0.

Thanks in advance

Upvotes: 4

Views: 537

Answers (2)

Juzmulti
Juzmulti

Reputation: 123

I found the problem.

I was loading an offline style by json file, but when I imported that json to my mapbox account and changed to an online URL, the issue was solved.

It was a strange problem...

Thank you!

Upvotes: 0

cammace
cammace

Reputation: 3168

So I tested some of your code but was unable to reproduce the problem your experiencing. My app began with the default style map and then on a user click it would change to one of my custom vector styles. I did change some of the code that might have inadvertently fixed the problem, the most notable change was instead of using Point I used LatLng. I also didn't create a marker list to add the markers to once created.

List<LatLng> route = new ArrayList<>();
route.add(new LatLng(29.751260, -95.373639));
route.add(new LatLng(29.752881, -95.374454));
route.add(new LatLng(29.755107, -95.374583));

//Adding markers
MarkerOptions currentMarker;
for(int i=0; i<route.size(); i++) {
    currentMarker = getMarkerFromPoint(route.get(i));
    mapView.addMarker(currentMarker);
    }

My getMarkerFromPoint() method:

private MarkerOptions getMarkerFromPoint(LatLng point) {
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(point);
    return markerOptions;
}

I hope this helps you resolve your problem and if I find the solution I'll edit this answer.

Upvotes: 1

Related Questions