Search in sources :

Example 1 with GeoBoundingBox

use of com.here.android.mpa.common.GeoBoundingBox 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 2 with GeoBoundingBox

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

the class MapFragmentView method roadSlopes.

/**
 * Method contains logic for extracting data about slopes and showing it on a route
 */
private void roadSlopes() {
    final java.util.Map<String, Integer> slopesMap = new HashMap<>();
    final java.util.Map<String, List<GeoCoordinate>> geometryMap = new HashMap<>();
    /*
         * Create a route plan for route calculation
         */
    RoutePlan rp = new RoutePlan();
    rp.addWaypoint(new RouteWaypoint(new GeoCoordinate(37.79513, -122.47603)));
    rp.addWaypoint(new RouteWaypoint(new GeoCoordinate(37.78166, -122.44450)));
    CoreRouter router = new CoreRouter();
    /*
         * For getting list of Link IDs routing should be forced to work online
         */
    router.setConnectivity(CoreRouter.Connectivity.ONLINE);
    router.calculateRoute(rp, new CoreRouter.Listener() {

        @Override
        public void onCalculateRouteFinished(List<RouteResult> list, RoutingError routingError) {
            if (routingError == RoutingError.NONE) {
                Route route = list.get(0).getRoute();
                /*
                     * Show route on the map and zoom to the route
                     */
                GeoBoundingBox bbox = route.getBoundingBox();
                map.addMapObject(new MapRoute(route));
                map.zoomTo(bbox, Map.Animation.NONE, 0);
                /*
                     * Get list of Link IDs for the route
                     */
                final List<Long> ids = route.getPermanentLinkIds();
                for (Long id : ids) {
                    pvids.add(id);
                }
                Set<String> layers = new HashSet<>(Arrays.asList(ADAS_LAYER, ROAD_GEOM_LAYER));
                PlatformDataRequest request = PlatformDataRequest.createBoundingBoxRequest(layers, bbox);
                request.execute(new PlatformDataRequest.Listener<PlatformDataResult>() {

                    @Override
                    public void onCompleted(PlatformDataResult data, PlatformDataRequest.Error error) {
                        if (error == null) {
                            /*
                                 * Process route geometry from PDE
                                 */
                            PlatformDataItemCollection roadDataCollection = data.get(ROAD_GEOM_LAYER);
                            for (PlatformDataItem item : roadDataCollection) {
                                geometryMap.put(item.getLinkId(), item.getCoordinates());
                            }
                            /*
                                 * Process ADAS data from PDE
                                 */
                            PlatformDataItemCollection adasDataCollection = data.get(ADAS_LAYER);
                            for (PlatformDataItem item : adasDataCollection) {
                                List<String> values = new ArrayList<>();
                                /*
                                     * Split slopes data
                                     */
                                StringTokenizer tokenizer = new StringTokenizer(item.get("SLOPES"));
                                while (tokenizer.hasMoreTokens()) {
                                    String token = tokenizer.nextToken(",");
                                    /*
                                         * Filter out invalid data
                                         */
                                    if (!token.equals("NULL") && !token.equals("1000000000")) {
                                        values.add(token);
                                    }
                                }
                                /*
                                     * Mark slopes data if it contains either high or low value
                                     */
                                int max = 0;
                                int min = 0;
                                for (String str : values) {
                                    int temp = Integer.valueOf(str);
                                    if (temp > max)
                                        max = temp;
                                    if (temp < min)
                                        min = temp;
                                }
                                if ((min * -1) > max && min <= -5_000)
                                    slopesMap.put(item.getLinkId(), LOW_COLOR);
                                else if ((min * -1) < max && max >= 5_000)
                                    slopesMap.put(item.getLinkId(), HIGH_COLOR);
                            }
                            /*
                                 * Process list of geometry
                                 * find route segment with high or low slopes value
                                 * and add this geometry to the list
                                 */
                            List<MapObject> polylines = new ArrayList<>();
                            for (java.util.Map.Entry<String, List<GeoCoordinate>> entry : geometryMap.entrySet()) {
                                if (pvids.contains(Long.parseLong(entry.getKey()))) {
                                    GeoPolyline polyline = new GeoPolyline();
                                    polyline.add(entry.getValue());
                                    MapPolyline line = new MapPolyline(polyline);
                                    if (slopesMap.containsKey(entry.getKey())) {
                                        line.setLineColor(slopesMap.get(entry.getKey()));
                                        line.setLineWidth(15);
                                        polylines.add(line);
                                    }
                                }
                            }
                            /*
                                 * Show a list of slopes geometry on the map
                                 */
                            map.addMapObjects(polylines);
                        } else {
                            /*
                                 * Process PDE request error
                                 */
                            Log.i(TAG, "PDE error: " + error.getFaultCode());
                            Log.i(TAG, "PDE error: " + error.getMessage());
                            Log.i(TAG, "PDE error: " + error.getResponseCode());
                            Log.i(TAG, "PDE error: " + error.getType().toString());
                        }
                    }
                });
            } else {
                Log.e(TAG, "Routing error: " + routingError);
            }
        }

        @Override
        public void onProgress(int i) {
            Log.i(TAG, String.format("Route calculation progress: %d%%", i));
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PlatformDataItemCollection(com.here.android.mpa.pde.PlatformDataItemCollection) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) RouteResult(com.here.android.mpa.routing.RouteResult) PlatformDataResult(com.here.android.mpa.pde.PlatformDataResult) ArrayList(java.util.ArrayList) List(java.util.List) RoutePlan(com.here.android.mpa.routing.RoutePlan) MapObject(com.here.android.mpa.mapping.MapObject) Route(com.here.android.mpa.routing.Route) MapRoute(com.here.android.mpa.mapping.MapRoute) PlatformDataItem(com.here.android.mpa.pde.PlatformDataItem) MapRoute(com.here.android.mpa.mapping.MapRoute) CoreRouter(com.here.android.mpa.routing.CoreRouter) RoutingError(com.here.android.mpa.routing.RoutingError) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) StringTokenizer(java.util.StringTokenizer) RoutingError(com.here.android.mpa.routing.RoutingError) PlatformDataRequest(com.here.android.mpa.pde.PlatformDataRequest) MapPolyline(com.here.android.mpa.mapping.MapPolyline) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox) HashMap(java.util.HashMap) Map(com.here.android.mpa.mapping.Map) GeoPolyline(com.here.android.mpa.common.GeoPolyline)

Example 3 with GeoBoundingBox

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

the class MapFragmentView method createPolygon.

/**
 * Create a MapPolygon and add the MapPolygon to active map view.
 */
private void createPolygon() {
    // create an bounding box centered at current cent
    GeoBoundingBox boundingBox = new GeoBoundingBox(m_map.getCenter(), 1000, 1000);
    // add boundingbox's four vertices to list of Geocoordinates.
    List<GeoCoordinate> coordinates = new ArrayList<GeoCoordinate>();
    coordinates.add(boundingBox.getTopLeft());
    coordinates.add(new GeoCoordinate(boundingBox.getTopLeft().getLatitude(), boundingBox.getBottomRight().getLongitude(), boundingBox.getTopLeft().getAltitude()));
    coordinates.add(boundingBox.getBottomRight());
    coordinates.add(new GeoCoordinate(boundingBox.getBottomRight().getLatitude(), boundingBox.getTopLeft().getLongitude(), boundingBox.getTopLeft().getAltitude()));
    // create GeoPolygon with list of GeoCoordinates.
    GeoPolygon geoPolygon = new GeoPolygon(coordinates);
    // create MapPolygon with GeoPolygon.
    m_polygon = new MapPolygon(geoPolygon);
    // set line color, fill color and line width
    m_polygon.setLineColor(Color.RED);
    m_polygon.setFillColor(Color.GRAY);
    m_polygon.setLineWidth(12);
    // add MapPolygon to map.
    m_map.addMapObject(m_polygon);
}
Also used : MapPolygon(com.here.android.mpa.mapping.MapPolygon) ArrayList(java.util.ArrayList) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox) GeoPolygon(com.here.android.mpa.common.GeoPolygon)

Example 4 with GeoBoundingBox

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

the class MapFragmentView method createPolyline.

/**
 * Create a MapPolyline and add the MapPolyline to active map view.
 */
private void createPolyline() {
    // create boundingBox centered at current location
    GeoBoundingBox boundingBox = new GeoBoundingBox(m_map.getCenter(), 1000, 1000);
    // add boundingBox's top left and bottom right vertices to list of GeoCoordinates
    List<GeoCoordinate> coordinates = new ArrayList<GeoCoordinate>();
    coordinates.add(boundingBox.getTopLeft());
    coordinates.add(boundingBox.getBottomRight());
    // create GeoPolyline with list of GeoCoordinates
    GeoPolyline geoPolyline = new GeoPolyline(coordinates);
    m_polyline = new MapPolyline(geoPolyline);
    m_polyline.setLineColor(Color.BLUE);
    m_polyline.setLineWidth(12);
    // add GeoPolyline to current active map
    m_map.addMapObject(m_polyline);
}
Also used : ArrayList(java.util.ArrayList) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) MapPolyline(com.here.android.mpa.mapping.MapPolyline) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox) GeoPolyline(com.here.android.mpa.common.GeoPolyline)

Example 5 with GeoBoundingBox

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

the class MapFragmentView method calculateRoute.

private void calculateRoute() {
    /*
         * Initialize a RouteOption. HERE Mobile 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
         */
    FTCRRouteOptions routeOptions = new FTCRRouteOptions();
    /* Other transport modes are also available e.g Pedestrian */
    routeOptions.setTransportMode(FTCRRouteOptions.TransportMode.CAR);
    /* Calculate the shortest route available. */
    routeOptions.setRouteType(FTCRRouteOptions.Type.SHORTEST);
    /* Define waypoints for the route */
    RouteWaypoint startPoint = new RouteWaypoint(m_startPoint);
    RouteWaypoint destination = new RouteWaypoint(m_endPoint);
    /* Initialize a RoutePlan */
    List<RouteWaypoint> routePoints = new ArrayList<>();
    routePoints.add(startPoint);
    routePoints.add(destination);
    FTCRRoutePlan routePlan = new FTCRRoutePlan(routePoints, routeOptions);
    /*
          Set the name of the map overlay. It has to be the same that is used for uploading
          the custom roads to the fleet telematics server.
         */
    routePlan.setOverlay(OVERLAY_NAME);
    if (m_routeTask != null) {
        m_routeTask.cancel();
    }
    m_routeTask = m_router.calculateRoute(routePlan, new FTCRRouter.Listener() {

        @Override
        public void onCalculateRouteFinished(@NonNull List<FTCRRoute> routeResults, @NonNull FTCRRouter.ErrorResponse errorResponse) {
            /* Calculation is done. Let's handle the result */
            if (errorResponse.getErrorCode() == RoutingError.NONE) {
                if (routeResults.get(0) != null) {
                    /* Create a FTCRMapRoute so that it can be placed on the map */
                    m_mapRoute = new FTCRMapRoute(routeResults.get(0));
                    /* Add the FTCRMapRoute 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).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: " + errorResponse.getErrorCode() + ",\nmessage: " + errorResponse.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    });
}
Also used : OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) FTCRMapRoute(com.here.android.mpa.mapping.FTCRMapRoute) NonNull(androidx.annotation.NonNull) ArrayList(java.util.ArrayList) FTCRRoutePlan(com.here.android.mpa.ftcr.FTCRRoutePlan) ArrayList(java.util.ArrayList) List(java.util.List) FTCRRouteOptions(com.here.android.mpa.ftcr.FTCRRouteOptions) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox)

Aggregations

GeoBoundingBox (com.here.android.mpa.common.GeoBoundingBox)10 GeoCoordinate (com.here.android.mpa.common.GeoCoordinate)9 ArrayList (java.util.ArrayList)7 RouteWaypoint (com.here.android.mpa.routing.RouteWaypoint)4 List (java.util.List)4 GeoPolyline (com.here.android.mpa.common.GeoPolyline)3 MapPolyline (com.here.android.mpa.mapping.MapPolyline)3 GeoPolygon (com.here.android.mpa.common.GeoPolygon)2 OnEngineInitListener (com.here.android.mpa.common.OnEngineInitListener)2 Map (com.here.android.mpa.mapping.Map)2 MapMarker (com.here.android.mpa.mapping.MapMarker)2 MapPolygon (com.here.android.mpa.mapping.MapPolygon)2 MapRoute (com.here.android.mpa.mapping.MapRoute)2 PlatformDataItemCollection (com.here.android.mpa.pde.PlatformDataItemCollection)2 PlatformDataRequest (com.here.android.mpa.pde.PlatformDataRequest)2 PlatformDataResult (com.here.android.mpa.pde.PlatformDataResult)2 CoreRouter (com.here.android.mpa.routing.CoreRouter)2 RoutePlan (com.here.android.mpa.routing.RoutePlan)2 RouteResult (com.here.android.mpa.routing.RouteResult)2 RoutingError (com.here.android.mpa.routing.RoutingError)2