osm地图绘制路线

时间:2019-02-12 15:35:28

标签: java android

我有很多要点,我想用osm画一条路线(如导航)。现在,我仅绘制这些点的标记,但无法绘制路线。这是我在地图上绘制标记的全部功能:

 private class GetOsmMarker extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);
        }

        @Override
        protected Void doInBackground(Void... params) {


            build.set(true);
            anotherOverlayItemArray1.clear();
            anotherOverlayItemArray.clear();
            activeOverlayItemArray1.clear();
            if (singleton == null)
                singleton = Singleton.getInstance();
            if (singleton != null && singleton.getListaVisible() != null) {

                currentNumber = -1;
                currentNumber = singleton.getListaVisible().indexOf(singleton.getCurrentObject());

                for (ObjectDefExtends object : singleton.getListaVisible()) {
                    if (object.lon == null) {
                        object.lon = 0.0;
                    }
                    if (object.lat == null) object.lat = 0.0;
                    if (object == Singleton.getInstance().currentObject && object.visible) {
                        activeOverlayItemArray1.add(new OverlayItem(object.symbol, object.name, new GeoPoint(object.lat, object.lon)));
                        pasekWidoczny = true;
                    }
                    if (object.visible) {
                        anotherOverlayItemArray1.add(new OverlayItem(object.symbol, object.name, new GeoPoint(object.lat, object.lon)));
                    }
                }

                mapView.getOverlays().remove(anotherItemizedIconOverlay);
                mapView.getOverlays().remove(mPin);
                mapView.getOverlays().clear();


                anotherItemizedIconOverlay1 = new ItemizedIconOverlay<>(anotherOverlayItemArray1, newMarker, new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
                    @Override
                    public boolean onItemSingleTapUp(int index, OverlayItem item) {

                        currentNumber = index;
                        mapView.getOverlays().remove(mPin);
                        centrowac.set(true);
                        centerOnTheObject(currentNumber);
                        singleton.setCurrentObjectIndex(index);
                        updateFields();
                        mapView.getOverlays().remove(activeItemizedIconOverlay);
                        mapView.getOverlays().remove(activeItemizedIconOverlay1);
                        pasekWidoczny = true;
                        dolny_pasek.setVisibility(View.VISIBLE);
                        mPin.hideInfoWindow();
                        mapView.getOverlays().remove(mPin);
                        mPin.setPosition(anotherItemizedIconOverlay.getItem(index).getPoint());
                        mPin.setTitle(anotherItemizedIconOverlay.getItem(index).getTitle() + "  ");
                        Singleton.getInstance().setCurrentObjectIndex(currentNumber);
                        editor.putInt("index", getCurrentIndexObject());
                        editor.commit();
                        InfoWindow infoWindow = new MyInfoWindow(R.layout.bonuspack_bubble, mapView, anotherItemizedIconOverlay.getItem(index).getSnippet() + "  ");
                        mPin.setInfoWindow(infoWindow);
                        mPin.setIcon(new BitmapDrawable(getResources(), RotateMyBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.res2), Singleton.getInstance().listaVisible.get(currentNumber).azimuth)));
                        mPin.showInfoWindow();
                        mapView.getOverlays().add(mPin);
                        mapView.invalidate();

                        return true;
                    }

                    @Override
                    public boolean onItemLongPress(int index, OverlayItem item) {
                        return false;
                    }
                }, mResourceProxy);

                for (int a = 0; a < anotherItemizedIconOverlay1.size(); a++) {

                    Drawable drawable = null;
                    if (singleton.listaVisible.size() > a) {
                        int aa = (int) (Math.rint((double) singleton.listaVisible.get(a).azimuth / 10) * 10);


                        Marker marker = new Marker(mapView);
                        marker.setIcon(drawable);
                        marker.setSnippet(anotherItemizedIconOverlay1.getItem(a).getTitle());
                        marker.setPosition(anotherItemizedIconOverlay1.getItem(a).getPoint());
                        InfoWindow infoWindow = new MyInfoWindow(R.layout.bonuspack_bubble, mapView, anotherItemizedIconOverlay1.getItem(a).getSnippet() + "  ");
                        marker.setInfoWindow(infoWindow);

                        if (marker.getPosition() != null)
                            if (marker.getPosition().getLongitude() != 0.0)
                                mapView.getOverlays().add(marker);

                        if (anotherItemizedIconOverlay1 != null) {
                            anotherItemizedIconOverlay1.getItem(a).setMarker(null);
                            anotherItemizedIconOverlay1.getItem(a).setMarker(drawable);
                            anotherItemizedIconOverlay1.getItem(a).setMarkerHotspot(CENTER);
                        }
                    }

                    anotherItemizedIconOverlay = anotherItemizedIconOverlay1;
                }
            }
            return null;
        }
    } 

我也可以获得带有点的gpx文件,但是仅设置标记就无法绘制路线。我想画一条像导航的路线,并且要显示我当前的位置

0 个答案:

没有答案