Domanda

I have a List with LatLng objects that form a route I want to draw on my map. I am using a SupportMapFragment and I call this method below on onActivityCreated. I have another method called from there that creates markers and that one is executed fine but my method below does not draw the polyline. I have searched for examples but could not find any that suit my needs. Can someone please point out what I'm doing wrong here?

private void drawRoute() {
    List<LatLng> latLngs = CoordinateEntity.getRouteLatLngs();
    PolylineOptions line = new PolylineOptions();
    line.width(5);
    line.color(Color.RED);

    for (LatLng latLng : latLngs) {
        line.add(latLng);
    }

    getMap().addPolyline(line);
}

I have looked at this and other similar examples and all follow this code pattern

mMap.addPolyline(new PolylineOptions()
  .add(new LatLng(lats, lons), new LatLng(late,lone))
  .width(5)
  .color(color));

Is this the only way a Polyline can be added to the map?

È stato utile?

Soluzione

Found my problem.

I had the play services jar added to my project and for some reason everything of the maps V2 api worked except drawing lines.

I then added the play services project as a dependency and after I did that everything worked.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top