Here you can see how to set up your project to support Google Maps get a API key and from the official documentation of the class Polilyne and the creation of forms , you can basically see how to draw a Polyline
in the following way . Remember that the Polyline
must be modified from the main thread or a IllegalStateException
will be released at run time:
GoogleMap map;
// ... get a map.
// Add a thin red line from London to New York.
Polyline line = map.addPolyline(new PolylineOptions()
.add(new LatLng(51.5, -0.1), new LatLng(40.7, -74.0))
.width(5)
.color(Color.RED));
A complete example :
public class PolylineDemoActivity extends AppCompatActivity
implements OnMapReadyCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {...}
@Override
public void onMapReady(GoogleMap map) {
// Override the default content description on the view, for accessibility mode.
// Ideally this string would be localised.
map.setContentDescription("Google Map with polylines.");
// A simple polyline with the default options from Melbourne-Adelaide-Perth.
map.addPolyline((new PolylineOptions())
.add(MELBOURNE, ADELAIDE, PERTH));
// A geodesic polyline that goes around the world.
mClickablePolyline = map.addPolyline((new PolylineOptions())
.add(LHR, AKL, LAX, JFK, LHR)
.width(5)
.color(Color.BLUE)
.geodesic(true)
.clickable(mClickabilityCheckbox.isChecked()));
// Rectangle centered at Sydney. This polyline will be mutable.
int radius = 5;
PolylineOptions options = new PolylineOptions()
.add(new LatLng(SYDNEY.latitude + radius, SYDNEY.longitude + radius))
.add(new LatLng(SYDNEY.latitude + radius, SYDNEY.longitude - radius))
.add(new LatLng(SYDNEY.latitude - radius, SYDNEY.longitude - radius))
.add(new LatLng(SYDNEY.latitude - radius, SYDNEY.longitude + radius))
.add(new LatLng(SYDNEY.latitude + radius, SYDNEY.longitude + radius));
// Move the map so that it is centered on the mutable polyline.
map.moveCamera(CameraUpdateFactory.newLatLng(SYDNEY));
}
Note: I leave links to the official documentation because Google has a bad (but necessary) habit of changing certain configuration procedures from time to time.
I hope it helps. greetings