gpt4 book ai didi

java - 单击时导航到标记 OSMdroid Android

转载 作者:行者123 更新时间:2023-12-02 12:02:10 33 4
gpt4 key购买 nike

我刚刚编写了一些代码来为 map 上的所有标记设置 onclick 监听器(我想在单击标记时导航到该标记)。然而,该方法似乎不起作用 - 事实上,我弹出了一些 Toast 进行调试,但它们似乎也没有打印。希望能对我所缺少的内容提供一些意见...我只是在 onCreate() 中调用 navigatorToMarkers。

//method to set onclicks for markers - when you click one, you navigate to it.
private void navigateToMarkers(){
for(int i=0; i<bookMap.getOverlays().size(); i++){
if(bookMap.getOverlays().get(i) instanceof Marker){
((Marker) bookMap.getOverlays().get(i)).setOnMarkerClickListener(new Marker.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker, MapView mapView) {
DrawRoad drawRoad = new DrawRoad(getCurrentLocation(), marker.getPosition());
drawRoad.execute();

Toast.makeText(MapActivity.this, "Marker clicked!", Toast.LENGTH_SHORT).show();

return true;
}
});
}
}


}

//we do this in a different thread as it takes some amount of processing power to get route to ucd.
private class DrawRoad extends AsyncTask<Void, Void, Road> {
GeoPoint startPoint;
GeoPoint endPoint;

public DrawRoad(GeoPoint startPoint, GeoPoint endPoint){
this.startPoint = startPoint;
this.endPoint = endPoint;
}

@Override
protected Road doInBackground(Void... voids) {
RoadManager roadManager = new OSRMRoadManager(MapActivity.this);

ArrayList<GeoPoint> waypoints = new ArrayList<>();
waypoints.add(startPoint);
waypoints.add(endPoint);

Road road = roadManager.getRoad(waypoints);

return road;
}

protected void onPostExecute(Road road){
updateUIWithRoad(road);
}
}

最佳答案

您的代码是正确的,它应该可以工作。

使用哪个 osmdroid 版本?

调试时,您能否检查一下是否到达了以下行:

((Marker) bookMap.getOverlays().get(i)).setOnMarkerClickListener(

关于java - 单击时导航到标记 OSMdroid Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47167058/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com