现在我正致力于移动应用程序,它以特定间隔获取gps位置,将位置数据发送到服务器。服务器根据此信息绘制Google路线图。
请帮我解决以下问题
有时候,在对面路线上标记的gps坐标实际上已经行进并使路线完全错误。
例如,我前往route like this (On google map)
在平行道路
上获取/标记B点我该如何解决这个问题?
答案 0 :(得分:0)
尝试亚历山大图书馆路线卓尔
编译'com.github.jd-alexander:library:1.1.0'
示例:
private void startRouting() {
LatLng origin = new LatLng(18.01455, -77.499333);
LatLng destination = new LatLng(18.0145600, -77.491333);
Routing routing = new Routing.Builder()
.travelMode(Routing.TravelMode.DRIVING)
.alternativeRoutes(false)
.withListener(new RoutingListener() {
@Override
public void onRoutingFailure(RouteException e) {
Log.e("onRoutingFailure: ", e.getMessage());
}
@Override
public void onRoutingStart() {
}
@Override
public void onRoutingSuccess(ArrayList<Route> routes, int shortestRouteIndex) {
if (routes != null && routes.size() > 0) {
for (Route route : routes) {
List<LatLng> latlngs = route.getPoints();
try {
Random rnd = new Random();
int color = Color.argb(200, rnd.nextInt(256), rnd.nextInt(256), 0);
/* int color1 = Color.argb(225, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
int color2 = Color.argb(225, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
int color3 = Color.argb(225, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));*/
mMap.addPolyline(new PolylineOptions().addAll(latlngs).color(color).width(12.0f));
} catch (Exception e) {
e.printStackTrace();
Log.e("onRoutingSuccess: ", e.getMessage());
Toast.makeText(MainActivity.this, "An internal error occurred!", Toast.LENGTH_SHORT).show();
}
}
//showBottomSheet(routes.get(shortestRouteIndex));
}
}
@Override
public void onRoutingCancelled() {
Log.e("onRoutingCancelled: ", "Routing cancelled");
}
})
.waypoints(origin, destination)
.build();
routing.execute();
}