I'm using Android SDK for maps in my application to render a Map for AndroidAuto inside a SurfaceCallBack. I can draw polilynes (directly), markers, etc. But I need a route from A to B.
This is my surfacecallback method
@Override
public void onSurfaceAvailable(@NonNull SurfaceContainer surfaceContainer) {
if (!isSurfaceReady(surfaceContainer)) {
return;
}
LatLng pointA = new LatLng(19.433364, -99.130031);
LatLng pointB = new LatLng(19.437652, -99.133152);
mSurface = surfaceContainer.getSurface();
VirtualDisplay virtualDisplay = mCarContext
.getSystemService(DisplayManager.class)
.createVirtualDisplay(
"nameVD",
surfaceContainer.getWidth(),
surfaceContainer.getHeight(),
surfaceContainer.getDpi(),
surfaceContainer.getSurface(),
DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY);
Presentation presentation = new Presentation(mCarContext, virtualDisplay.getDisplay());
NavigationViewForAuto navigationView = new NavigationViewForAuto(mCarContext);
navigationView.onCreate(null);
navigationView.onStart();
navigationView.onResume();
presentation.setContentView(navigationView);
presentation.show();
navigationView.getMapAsync(googleMap -> {
mBackgroundMap = googleMap;
centerMapOnCurrentLocation();
addRoute(pointA, pointB);
renderFrame(); // Render the frame once the map is ready
});
}
Im using this library:
implementation ("com.google.android.libraries.navigation:navigation:5.2.0")
AddRoute function just draw a line