我已通过带有[]的Google地图路由添加了当前位置,>
Routing routing = new Routing.Builder() .travelMode(Routing.TravelMode.DRIVING) .key(getResources().getString(R.string.google_maps_api)) .withListener(this) .waypoints(new LatLng(mLastKnownLocation.getLatitude(), mLastKnownLocation.getLongitude()), site_location) .alternativeRoutes(false) .build(); routing.execute(); @Override public void onRoutingSuccess(ArrayList<Route> route, int shortestRouteIndex) { if (polylines.size() > 0) { for (Polyline poly : polylines) { poly.remove(); } } polylines = new ArrayList<>(); //add route(s) to the map. for (int i = 0; i < route.size(); i++) { //In case of more than 5 alternative routes int colorIndex = i % COLORS.length; PolylineOptions polyOptions = new PolylineOptions(); polyOptions.color(getResources().getColor(COLORS[colorIndex])); polyOptions.width(10 + i * 13); polyOptions.addAll(route.get(i).getPoints()); Polyline polyline = googleMap.addPolyline(polyOptions); polylines.add(polyline); int distance = route.get(i).getDistanceValue(); if (distance < 1000){ totalKm.setText( distance+" Metres"); }else { totalKm.setText( (distance/1000) +" km"); } } LatLngBounds.Builder builder = new LatLngBounds.Builder(); builder.include(new LatLng(mLastKnownLocation.getLatitude(), mLastKnownLocation.getLongitude())); builder.include(site_marker.getPosition()); LatLngBounds bounds = builder.build(); CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 100); googleMap.animateCamera(cu); }
显示类似的行车路线>
但是我试图显示具有放大视图的默认谷歌地图行车图标,例如
我如何继续添加这样的地图,同时仍然保留折线以显示驾驶视图。
[我已通过Google地图路由添加了当前位置,并且路由路由= new Routing.Builder().travelMode(Routing.TravelMode.DRIVING).key(getResources()....
Android未提供像方向View
(图像2)那样的View
用于开发。如果要使用相同的View
,则可以通过传递源位置和目标位置来从应用程序启动默认地图应用程序这样的位置。
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);
除了Jinesh的答案,如果您仍想添加该标记用于开发,则需要在当前位置上设置自定义标记,并在每次调用onLocationChanged()回调时将其移动到新位置。稍微倾斜地图以获得google地图导航视图的确切外观,尽管您不会使用所有功能,但是值得尝试一下。