Search in sources :

Example 1 with GeoCoordinate

use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.

the class MapFragmentView method initMapFragment.

private void initMapFragment() {
    /* Locate the mapFragment UI element */
    m_mapFragment = (MapFragment) m_activity.getFragmentManager().findFragmentById(R.id.mapfragment);
    // Set path of isolated disk cache
    String diskCacheRoot = Environment.getExternalStorageDirectory().getPath() + File.separator + ".isolated-here-maps";
    // Retrieve intent name from manifest
    String intentName = "";
    try {
        ApplicationInfo ai = m_activity.getPackageManager().getApplicationInfo(m_activity.getPackageName(), PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;
        intentName = bundle.getString("INTENT_NAME");
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(this.getClass().toString(), "Failed to find intent name, NameNotFound: " + e.getMessage());
    }
    boolean success = com.here.android.mpa.common.MapSettings.setIsolatedDiskCacheRootPath(diskCacheRoot, intentName);
    if (!success) {
    // Setting the isolated disk cache was not successful, please check if the path is valid and
    // ensure that it does not match the default location
    // (getExternalStorageDirectory()/.here-maps).
    // Also, ensure the provided intent name does not match the default intent name.
    } else {
        if (m_mapFragment != null) {
            /* Initialize the MapFragment, results will be given via the called back. */
            m_mapFragment.init(new OnEngineInitListener() {

                @Override
                public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
                    if (error == Error.NONE) {
                        m_map = m_mapFragment.getMap();
                        m_map.setCenter(new GeoCoordinate(49.259149, -123.008555), Map.Animation.NONE);
                        // Put this call in Map.onTransformListener if the animation(Linear/Bow)
                        // is used in setCenter()
                        m_map.setZoomLevel(13.2);
                        /*
                         * Get the NavigationManager instance.It is responsible for providing voice
                         * and visual instructions while driving and walking
                         */
                        m_navigationManager = NavigationManager.getInstance();
                    } else {
                        Toast.makeText(m_activity, "ERROR: Cannot initialize Map with error " + error, Toast.LENGTH_LONG).show();
                    }
                }
            });
        }
    }
}
Also used : PackageManager(android.content.pm.PackageManager) Bundle(android.os.Bundle) ApplicationInfo(android.content.pm.ApplicationInfo) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener)

Example 2 with GeoCoordinate

use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.

the class MapFragmentView method createRoute.

/* Creates a route from 4350 Still Creek Dr to Langley BC with highways disallowed */
private void createRoute() {
    /* Initialize a CoreRouter */
    CoreRouter coreRouter = new CoreRouter();
    /* Initialize a RoutePlan */
    RoutePlan routePlan = new RoutePlan();
    /*
         * Initialize a RouteOption.HERE SDK allow users to define their own parameters for the
         * route calculation,including transport modes,route types and route restrictions etc.Please
         * refer to API doc for full list of APIs
         */
    RouteOptions routeOptions = new RouteOptions();
    /* Other transport modes are also available e.g Pedestrian */
    routeOptions.setTransportMode(RouteOptions.TransportMode.CAR);
    /* Disable highway in this route. */
    routeOptions.setHighwaysAllowed(false);
    /* Calculate the shortest route available. */
    routeOptions.setRouteType(RouteOptions.Type.SHORTEST);
    /* Calculate 1 route. */
    routeOptions.setRouteCount(1);
    /* Finally set the route option */
    routePlan.setRouteOptions(routeOptions);
    /* Define waypoints for the route */
    /* START: 4350 Still Creek Dr */
    RouteWaypoint startPoint = new RouteWaypoint(new GeoCoordinate(49.259149, -123.008555));
    /* END: Langley BC */
    RouteWaypoint destination = new RouteWaypoint(new GeoCoordinate(49.073640, -122.559549));
    /* Add both waypoints to the route plan */
    routePlan.addWaypoint(startPoint);
    routePlan.addWaypoint(destination);
    /* Trigger the route calculation,results will be called back via the listener */
    coreRouter.calculateRoute(routePlan, new Router.Listener<List<RouteResult>, RoutingError>() {

        @Override
        public void onProgress(int i) {
        /* The calculation progress can be retrieved in this callback. */
        }

        @Override
        public void onCalculateRouteFinished(List<RouteResult> routeResults, RoutingError routingError) {
            /* Calculation is done.Let's handle the result */
            if (routingError == RoutingError.NONE) {
                if (routeResults.get(0).getRoute() != null) {
                    /* Create a MapRoute so that it can be placed on the map */
                    m_mapRoute = new MapRoute(routeResults.get(0).getRoute());
                    /* Show the maneuver number on top of the route */
                    m_mapRoute.setManeuverNumberVisible(true);
                    /* Add the MapRoute to the map */
                    m_map.addMapObject(m_mapRoute);
                    /*
                                 * We may also want to make sure the map view is orientated properly
                                 * so the entire route can be easily seen.
                                 */
                    GeoBoundingBox gbb = routeResults.get(0).getRoute().getBoundingBox();
                    m_map.zoomTo(gbb, Map.Animation.NONE, Map.MOVE_PRESERVE_ORIENTATION);
                } else {
                    Toast.makeText(m_activity, "Error:route results returned is not valid", Toast.LENGTH_LONG).show();
                }
            } else {
                Toast.makeText(m_activity, "Error:route calculation returned error code: " + routingError, Toast.LENGTH_LONG).show();
            }
        }
    });
}
Also used : MapRoute(com.here.android.mpa.mapping.MapRoute) CoreRouter(com.here.android.mpa.routing.CoreRouter) CoreRouter(com.here.android.mpa.routing.CoreRouter) Router(com.here.android.mpa.routing.Router) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) RouteOptions(com.here.android.mpa.routing.RouteOptions) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) RoutingError(com.here.android.mpa.routing.RoutingError) RouteResult(com.here.android.mpa.routing.RouteResult) List(java.util.List) RoutePlan(com.here.android.mpa.routing.RoutePlan) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox)

Example 3 with GeoCoordinate

use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.

the class MapFragmentView method initMapFragment.

private void initMapFragment() {
    /* Locate the mapFragment UI element */
    m_mapFragment = (MapFragment) m_activity.getFragmentManager().findFragmentById(R.id.mapfragment);
    // Set path of isolated disk cache
    String diskCacheRoot = Environment.getExternalStorageDirectory().getPath() + File.separator + ".isolated-here-maps";
    // Retrieve intent name from manifest
    String intentName = "";
    try {
        ApplicationInfo ai = m_activity.getPackageManager().getApplicationInfo(m_activity.getPackageName(), PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;
        intentName = bundle.getString("INTENT_NAME");
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(this.getClass().toString(), "Failed to find intent name, NameNotFound: " + e.getMessage());
    }
    boolean success = com.here.android.mpa.common.MapSettings.setIsolatedDiskCacheRootPath(diskCacheRoot, intentName);
    if (!success) {
    // Setting the isolated disk cache was not successful, please check if the path is valid and
    // ensure that it does not match the default location
    // (getExternalStorageDirectory()/.here-maps).
    // Also, ensure the provided intent name does not match the default intent name.
    } else {
        if (m_mapFragment != null) {
            /* Initialize the MapFragment, results will be given via the called back. */
            m_mapFragment.init(new OnEngineInitListener() {

                @Override
                public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
                    if (error == Error.NONE) {
                        /* get the map object */
                        m_map = m_mapFragment.getMap();
                        /*
                         * Set the map center to the 4350 Still Creek Dr Burnaby BC (no animation).
                         */
                        m_map.setCenter(new GeoCoordinate(49.259149, -123.008555, 0.0), Map.Animation.NONE);
                        /* Set the zoom level to the average between min and max zoom level. */
                        m_map.setZoomLevel((m_map.getMaxZoomLevel() + m_map.getMinZoomLevel()) / 2);
                    } else {
                        Toast.makeText(m_activity, "ERROR: Cannot initialize Map with error " + error, Toast.LENGTH_LONG).show();
                    }
                }
            });
        }
    }
}
Also used : PackageManager(android.content.pm.PackageManager) Bundle(android.os.Bundle) ApplicationInfo(android.content.pm.ApplicationInfo) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener)

Example 4 with GeoCoordinate

use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.

the class MapFragmentView method addGeometry.

private void addGeometry() {
    // add some geometry to map using map center
    GeoCoordinate center = m_map.getCenter();
    // Create point geometry
    CLE2PointGeometry geometry = new CLE2PointGeometry(center);
    // Create map marker object
    MapMarker mapMarker = new MapMarker(center);
    m_geometryList.add(geometry);
    m_map.addMapObject(mapMarker);
}
Also used : MapMarker(com.here.android.mpa.mapping.MapMarker) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) CLE2PointGeometry(com.here.android.mpa.customlocation2.CLE2PointGeometry)

Example 5 with GeoCoordinate

use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.

the class NavigationController method createWaypointsFromFTCRGeometry.

private List<RouteWaypoint> createWaypointsFromFTCRGeometry(List<GeoCoordinate> ftcrRouteGeometry, List<RouteWaypoint> stopoves) {
    ArrayList<RouteWaypoint> sparseFTCRGeometryAsWaypoints = new ArrayList<>();
    int lastAddedStopoverIndex = 0;
    RouteWaypoint lastAddedStopover = stopoves.get(lastAddedStopoverIndex);
    RouteWaypoint nextStopover = stopoves.get(lastAddedStopoverIndex + 1);
    sparseFTCRGeometryAsWaypoints.add(lastAddedStopover);
    for (int i = 0; i < ftcrRouteGeometry.size(); i++) {
        GeoCoordinate curr = ftcrRouteGeometry.get(i);
        if (curr.distanceTo(lastAddedStopover.getNavigablePosition()) >= MIN_DISTANCE_BETWEEN_WAYPOINTS) {
            // use VIA waypoint just to advice SDK to calculate route through this geo point
            // no any event will be triggered on reaching this type of waypoint
            lastAddedStopover = new RouteWaypoint(curr, Type.VIA_WAYPOINT);
            sparseFTCRGeometryAsWaypoints.add(lastAddedStopover);
        }
        // also find and add stopover waupoints
        if (isFTCRGeometryPointCloseToStopover(nextStopover, curr)) {
            lastAddedStopover = nextStopover;
            lastAddedStopoverIndex = lastAddedStopoverIndex + 1;
            // lastAddedStopover has STOP type, so SDK will trigger needed events in guidance
            sparseFTCRGeometryAsWaypoints.add(lastAddedStopover);
            if (lastAddedStopoverIndex + 1 < stopoves.size()) {
                nextStopover = stopoves.get(lastAddedStopoverIndex + 1);
            } else {
                nextStopover = null;
            }
        }
    }
    return sparseFTCRGeometryAsWaypoints;
}
Also used : ArrayList(java.util.ArrayList) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint)

Aggregations

GeoCoordinate (com.here.android.mpa.common.GeoCoordinate)50 OnEngineInitListener (com.here.android.mpa.common.OnEngineInitListener)17 DialogInterface (android.content.DialogInterface)12 RouteWaypoint (com.here.android.mpa.routing.RouteWaypoint)11 File (java.io.File)10 GeoBoundingBox (com.here.android.mpa.common.GeoBoundingBox)9 ArrayList (java.util.ArrayList)9 MapMarker (com.here.android.mpa.mapping.MapMarker)7 CoreRouter (com.here.android.mpa.routing.CoreRouter)7 List (java.util.List)7 MapRoute (com.here.android.mpa.mapping.MapRoute)6 RoutePlan (com.here.android.mpa.routing.RoutePlan)6 RouteOptions (com.here.android.mpa.routing.RouteOptions)5 RouteResult (com.here.android.mpa.routing.RouteResult)5 RoutingError (com.here.android.mpa.routing.RoutingError)5 ApplicationInfo (android.content.pm.ApplicationInfo)4 PackageManager (android.content.pm.PackageManager)4 Bundle (android.os.Bundle)4 GeoPolyline (com.here.android.mpa.common.GeoPolyline)4 Image (com.here.android.mpa.common.Image)4