我一直在尝试包含在Android应用中显示路线的功能,并且正在将此解决方案应用到我的应用中:
J2ME/Android/BlackBerry - driving directions, route between two locations
我基本上已经有了所有代码,但是在drawPath方法中我得到错误“类型Projection中的方法toPixels(GeoPoint,Point)不适用于参数(GeoPoint,Point)”下面的加星代码。这是代码:
public void drawPath(MapView mMapView, Canvas canvas)
{
int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
Paint paint = new Paint();
paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(3);
for (int i = 0; i < mPoints.size(); i++)
{
Point point = new Point();
mMapView.getProjection().*****toPixels*****(mPoints.get(i), point);
x2 = point.*****x*****;
y2 = point.*****y*****;
if (i > 0)
{
canvas.drawLine(x1, y1, x2, y2, paint);
}
x1 = x2;
y1 = y2;
}
}
我根本无法测试它,因为我无法对此错误进行排序,所以我不知道其他地方是否还有其他问题。但与此同时,如果有人知道为什么会弹出这个错误,那将非常感激。提前致谢!哦,如果有人需要查看我的其他代码或类别,请告诉我。
答案 0 :(得分:0)
here是我发布的一个很好的例子,你可以试试这个
答案 1 :(得分:0)
我曾尝试过这个源代码。
从源代码复制文件,在此之前不要更改任何内容。 不要按 Ctrl + Shift + O 自动加载库类。 有时,eclipse会导入错误的库。为什么?这是关于日食的另一个话题。
手动编辑所有这些行
import org.ci.geo.route.Road;
import org.ci.geo.route.RoadProvider;
将导入更改为您的包库名称。
然后编辑适合您的布局的这一行:
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
这是甜味的
TextView textView = (TextView) findViewById(R.id.description);
希望这会对你有所帮助