Search in sources :

Example 16 with GeoCoordinate

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

the class MapFragmentView method createRoute.

private void createRoute() {
    /* Initialize a CoreRouter */
    CoreRouter coreRouter = new CoreRouter();
    /* Initialize a RoutePlan */
    RoutePlan routePlan = new RoutePlan();
    /*
         * 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
         */
    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) {
                    m_route = routeResults.get(0).getRoute();
                    /* Create a MapRoute so that it can be placed on the map */
                    MapRoute mapRoute = new MapRoute(routeResults.get(0).getRoute());
                    /* Show the maneuver number on top of the route */
                    mapRoute.setManeuverNumberVisible(true);
                    /* Add the MapRoute to the map */
                    m_map.addMapObject(mapRoute);
                    /*
                                 * We may also want to make sure the map view is orientated properly
                                 * so the entire route can be easily seen.
                                 */
                    m_geoBoundingBox = routeResults.get(0).getRoute().getBoundingBox();
                    m_map.zoomTo(m_geoBoundingBox, Map.Animation.NONE, Map.MOVE_PRESERVE_ORIENTATION);
                    startNavigation();
                } 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) Router(com.here.android.mpa.routing.Router) CoreRouter(com.here.android.mpa.routing.CoreRouter) 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)

Example 17 with GeoCoordinate

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

the class MapFragmentView method initColorPropertyButton.

/**
 * Initialize change color property button to add customizable scheme which customizes airport
 * area's color.
 */
private void initColorPropertyButton() {
    m_colorBtn = (Button) m_activity.findViewById(R.id.color_button);
    m_colorBtn.setOnClickListener(new View.OnClickListener() {

        // if customizable scheme named "colorScheme" does not exist yet, create one
        // and set customizable scheme 's airport area color to be red for specific range
        // and set it to be current map scheme.
        @Override
        public void onClick(View v) {
            if (m_map != null && m_map.getCustomizableScheme(m_colorSchemeName) == null) {
                m_map.createCustomizableScheme(m_colorSchemeName, Map.Scheme.NORMAL_DAY);
                m_colorScheme = m_map.getCustomizableScheme(m_colorSchemeName);
            }
            ZoomRange range = new ZoomRange(0.0, 20.0);
            m_colorScheme.setVariableValue(CustomizableVariables.AirportArea.COLOR, Color.RED, range);
            m_map.setMapScheme(m_colorScheme);
            // set current center and zoom level to have a better view.
            m_map.setCenter(new GeoCoordinate(52.5588642, 13.2850454, 0.0), Map.Animation.NONE);
            m_map.setZoomLevel(12);
        }
    });
}
Also used : GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) ZoomRange(com.here.android.mpa.mapping.customization.ZoomRange) View(android.view.View)

Example 18 with GeoCoordinate

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

use of com.here.android.mpa.common.GeoCoordinate 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 20 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);
                        m_map.setZoomLevel(13.2);
                        // Show position indicator and accuracy aura
                        m_mapFragment.getPositionIndicator().setVisible(true).setAccuracyIndicatorVisible(true);
                        // Start the positioning manager
                        PositioningManager.getInstance().start(PositioningManager.LocationMethod.GPS_NETWORK);
                        // Create Map NLP object to control voice operations
                        // Pass Activity as a Context!!!
                        m_nlp = Nlp.getInstance();
                        m_myAsr = new MyASR(m_activity.getApplicationContext());
                        m_nlp.init(m_activity, m_mapFragment, null, m_myAsr, m_nlpListener);
                    } 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)

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