first of all, I want to apologize if I cannot make myself clear.
I have a problem using the HERE Maps SDK. I am not able to make my code work inside the onCreate statement, but outside the init() method for the map.
However, if I put the last block of code inside the init() and the end of the if-statement, everything works fine. I'm just wondering if I'm supposed to handle everything inside init(). That would get quite messy/crowded, I assume...
Here is my code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Search for the map fragment to finish setup by calling init()
mapFragment = (MapFragment)getFragmentManager().findFragmentById(R.id.mapfragment);
mapFragment.init(new OnEngineInitListener() {
@Override
public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
if (error == OnEngineInitListener.Error.NONE) {
// retrieve a reference of the map from the map fragment
map = mapFragment.getMap();
// Set the map center to the Berlin region
map.setCenter(new GeoCoordinate(52.520413, 13.405218, 0.0), Map.Animation.LINEAR);
// Set the zoom level to the average between min and max
map.setZoomLevel((map.getMaxZoomLevel() + map.getMinZoomLevel()) / 1.5);
map.getMapTransitLayer().setMode(MapTransitLayer.Mode.EVERYTHING);
mapFragment.getMapGesture().addOnGestureListener(new MyOnGestureListener());
posManager = PositioningManager.getInstance();
// Register positioning listener
posManager.addListener(new WeakReference<>(positionListener));
posManager.start(PositioningManager.LocationMethod.GPS_NETWORK);
posManager.getPosition();
map.getPositionIndicator().setVisible(true);
} else {
System.out.println("ERROR: Cannot initialize Map Fragment");
}
}
});
RouteManager rm = new RouteManager();
RoutePlan routePlan = new RoutePlan();
routePlan.addWaypoint(new GeoCoordinate(posManager.getLastKnownPosition().getCoordinate()));
routePlan.addWaypoint(new GeoCoordinate(52.520413, 13.405218));
// Create the RouteOptions and set its transport mode & routing type
RouteOptions routeOptions = new RouteOptions();
routeOptions.setTransportMode(RouteOptions.TransportMode.CAR);
routeOptions.setRouteType(RouteOptions.Type.FASTEST);
routePlan.setRouteOptions(routeOptions);
// Calculate the route
rm.calculateRoute(routePlan, new RouteListener());
}
After the semicolon of the init() statement, in the line where it says RouteManager rm = new RouteManager();
I get the following error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.here.android.tutorial.basicmapsolution/com.here.android.tutorial.basicmapsolution.BasicMapActivity}: com.here.android.mpa.common.UnintializedMapEngineException: Cannot created HERE SDK objects before MapEngine is initialized. See MapEngine.init()
Caused by: com.here.android.mpa.common.UnintializedMapEngineException: Cannot created HERE SDK objects before MapEngine is initialized. See MapEngine.init()