OSMDroid PathOverlay

Today I am looking forward to how to use PathOverlay in OSMDroid.

I can not find any explanation of how this works.

I need to create a suggested route (not the same as a navigation system), just a kick starting at a point, follow the β€œpattern” and then go back to the starting point.

Just like this (drawn on google maps):

Circuit

I am here to ask what is the right way to do this, indicating my own path, performing the turns that I want.

Thanks!

+6
source share
2 answers

He would draw a series of straight lines for you on top of the map, so you need to know the latitude and longitude of all your road junctions (and everywhere they are bent from a straight line). Add all these points to the overlay. For example, this code will draw a rectangle in the center of London.

public class OsmdroidDemoMap extends Activity { private MapView mMapView; private MapController mMapController; int mIncr = 10000; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.osm_main); mMapView = (MapView) findViewById(R.id.mapview); mMapView.setTileSource(TileSourceFactory.MAPNIK); mMapView.setBuiltInZoomControls(true); mMapView.setMultiTouchControls(true); mMapController = mMapView.getController(); mMapController.setZoom(13); GeoPoint gPt0 = new GeoPoint(51500000, -150000); GeoPoint gPt1 = new GeoPoint(gPt0.getLatitudeE6()+ mIncr, gPt0.getLongitudeE6()); GeoPoint gPt2 = new GeoPoint(gPt0.getLatitudeE6()+ mIncr, gPt0.getLongitudeE6() + mIncr); GeoPoint gPt3 = new GeoPoint(gPt0.getLatitudeE6(), gPt0.getLongitudeE6() + mIncr); mMapController.setCenter(gPt0); PathOverlay myPath = new PathOverlay(Color.RED, this); myPath.addPoint(gPt0); myPath.addPoint(gPt1); myPath.addPoint(gPt2); myPath.addPoint(gPt3); myPath.addPoint(gPt0); mMapView.getOverlays().add(myPath); } } 

.

+29
source

Here is a tutorial on how to draw a road using Polyline in OSMBonusPack: https://github.com/MKergall/osmbonuspack/wiki/Tutorial_1

It is quite simple, and I have successfully used this in my application.

My code based on this tutorial is as follows:

  RoadManager roadManager = new OSRMRoadManager(); ArrayList<GeoPoint> track = new ArrayList<>(); // TODO: Fill the list with your track points Road road = roadManager.getRoad(track); Polyline roadOverlay = RoadManager.buildRoadOverlay(road, context); mapView.getOverlays().add(roadOverlay); mapView.invalidate(); 
+4
source

Source: https://habr.com/ru/post/912923/


All Articles