java OSMDroid PathOverlay
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10104581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OSMDroid PathOverlay
提问by silentw
Today I'm looking forward of how to use PathOverlay in OSMDroid.
今天我很期待如何在OSMDroid中使用PathOverlay。
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.
我在这里问什么是正确的方法来做到这一点,指定一个自定义路径,做我想要的转弯。
Thanks!
谢谢!
回答by NickT
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);
}
}
.
.
回答by CI Apps
Here is the tutorial how to draw the road with Polyline in OSMBonusPack: https://github.com/MKergall/osmbonuspack/wiki/Tutorial_1
这是如何在 OSMBonusPack 中使用折线绘制道路的教程:https: //github.com/MKergall/osmbonuspack/wiki/Tutorial_1
It is pretty easy and I have successfully used this in my app.
这很容易,我已经在我的应用程序中成功使用了它。
My code based on that tutorial is looking like this:
我基于该教程的代码如下所示:
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();