【问题标题】:Error while following osmbonuspack "Hello, Routing World!" tutorial跟随 osmbonuspack “你好,路由世界!”时出错教程
【发布时间】:2014-04-22 06:22:49
【问题描述】:

我使用 OSM 创建了一个简单的项目。地图显示了我当前的位置。现在我想创建从我当前位置到地图上特定点的导航。我正在尝试关注this tutorial

Polyline roadOverlay = RoadManager.buildRoadOverlay(road, this); 行中,我收到类似

的错误
Type mismatch: cannot convert from PathOverlay to Polyline

我在项目中使用了以下库:

1. osmdroid-android-4.1.jar
2. osmbonuspack_3.0.jar
3. slf4j-android-1.5.8.jar

这是MainActivity

import java.util.ArrayList;

import org.osmdroid.DefaultResourceProxyImpl;
import org.osmdroid.ResourceProxy;
import org.osmdroid.api.Polyline;
import org.osmdroid.bonuspack.routing.OSRMRoadManager;
import org.osmdroid.bonuspack.routing.Road;
import org.osmdroid.bonuspack.routing.RoadManager;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;


public class MainActivity extends Activity {

    MyItemizedOverlay myItemizedOverlay = null;

    double latitude;
    double longitude;

    // The MapView variable:
    private MapView m_mapView;

    GeoPoint startPoint;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


         GPSTracker tracker = new GPSTracker(this);
         if (tracker.canGetLocation() == false) {
         tracker.showSettingsAlert();
         } else {
         latitude = tracker.getLatitude();
         longitude = tracker.getLongitude();
         }


          // Find the MapView controller in that layout:
        m_mapView = (MapView) findViewById(R.id.mapview);

        //MapView mapView = new MapView(this, 256); //constructor
        m_mapView.setClickable(true);
        m_mapView.setBuiltInZoomControls(true);
           //setContentView(m_mapView); //displaying the MapView
           m_mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);
           m_mapView.getController().setZoom(15); //set initial zoom-level, depends on your need
           m_mapView.getController().setCenter(new GeoPoint(latitude, longitude));
           m_mapView.setUseDataConnection(true); 
           m_mapView.setMultiTouchControls(true);


           Drawable marker = getResources().getDrawable(R.drawable.pin_for_map);
             int markerWidth = marker.getIntrinsicWidth();
             int markerHeight = marker.getIntrinsicHeight();
             marker.setBounds(0, markerHeight, markerWidth, 0);

             ResourceProxy resourceProxy = new DefaultResourceProxyImpl(
             getApplicationContext());

             myItemizedOverlay = new MyItemizedOverlay(marker, resourceProxy);
             m_mapView.getOverlays().add(myItemizedOverlay);

             GeoPoint myPoint1 = new GeoPoint(latitude, longitude);
             myItemizedOverlay.addItem(myPoint1, "myPoint1", "myPoint1");

             startPoint = new GeoPoint(latitude, longitude);
    }

    //For routing
    public void osmRoute()
    {
        //road manager
        RoadManager roadManager = new OSRMRoadManager();

        //start and end points
        ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
        waypoints.add(startPoint);
        GeoPoint endPoint = new GeoPoint(48.4, -1.9);
        waypoints.add(endPoint);

        //etreive the road between those points
        Road road = roadManager.getRoad(waypoints);

        //build a Polyline with the route shape
        Polyline roadOverlay = RoadManager.buildRoadOverlay(road, this);
    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

这里是 activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <org.osmdroid.views.MapView
            android:id="@+id/mapview"
            android:layout_width="match_parent" 
            android:layout_height="match_parent"
            android:enabled="true"      
            android:clickable="true"
        />  
</RelativeLayout>

我哪里错了?我应该怎么做才能完成教程?

【问题讨论】:

    标签: java android navigation openstreetmap osmdroid


    【解决方案1】:

    除了 kurtzmarc 评论,你也没有使用正确版本的 OSMBonusPack:

    如果您使用的是 osmdroid-android-4.1.jar,那么您必须使用 OSMBonusPack v4.2.6 或更高版本。

    下载最新版本(v4.4),而不是过时的版本。

    【讨论】:

    【解决方案2】:

    您是否有错误的折线导入?尝试添加:

    import org.osmdroid.bonuspack.overlays.Polyline;
    

    并摆脱:

    import org.osmdroid.api.Polyline;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-13
      • 1970-01-01
      相关资源
      最近更新 更多