OSMDroid PathOverlayOSMDroid、PathOverlay

2023-09-04 07:39:07 作者:处事稳妥.

今天,我在寻找如何使用PathOverlay在OSMDroid着。

Today I'm looking forward of how to use PathOverlay in OSMDroid.

我找不到它是如何工作的任何解释。

I can't find any explanation of how it works.

我需要创建一个建议路线(不喜欢导航系统),只是行程开始时在一个点上,做一个电路,然后返回到起点。

I need to create a suggested route (not like navigation system), just a stroke begining at a point, do a "circuit" and then return to the starting point.

就这样(在谷歌地图绘制):

Just like this (drawn in google maps):

我在这里要问什么是正确的方式做到这一点,指定自定义路径,做我想要的转弯。

I'm here to ask what's the correct way to do this, specifying a custom path, doing the turns I want.

谢谢!

推荐答案

这将吸引一系列的直线为你在地图的上面,所以你需要知道你所有的路口的纬度和经度(和无处不在它们弯曲远离直线)。所有这些点加入到覆盖。作为一个例子,这个code将借鉴伦敦中部的一个长方形的盒子。

It will 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 bend away from a straight line). Add all these points to the overlay. As an example, this code will draw a rectangular box in central 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);
    }
}