Search in sources :

Example 1 with Image

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

the class MapFragmentView method createMapMarker.

/**
 * create a MapMarker and add the MapMarker to active map view.
 */
private void createMapMarker() {
    // create an image from cafe.png.
    Image marker_img = new Image();
    try {
        marker_img.setImageResource(R.drawable.cafe);
    } catch (IOException e) {
        e.printStackTrace();
    }
    // create a MapMarker centered at current location with png image.
    m_map_marker = new MapMarker(m_map.getCenter(), marker_img);
    // add a MapMarker to current active map.
    m_map.addMapObject(m_map_marker);
}
Also used : MapMarker(com.here.android.mpa.mapping.MapMarker) IOException(java.io.IOException) Image(com.here.android.mpa.common.Image)

Example 2 with Image

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

the class MapFragmentView method calculateAndStartNavigation.

private void calculateAndStartNavigation() {
    if (m_map == null) {
        Toast.makeText(m_activity, "Map is not ready yet", Toast.LENGTH_SHORT).show();
        return;
    }
    if (NavigationManager.getInstance().getRunningState() == NavigationManager.NavigationState.RUNNING) {
        Toast.makeText(m_activity, "Navigation is currently running", Toast.LENGTH_SHORT).show();
        return;
    }
    final RoutePlan routePlan = new RoutePlan();
    // these two waypoints cover suburban roads
    routePlan.addWaypoint(new RouteWaypoint(new GeoCoordinate(48.960497, 2.47351)));
    routePlan.addWaypoint(new RouteWaypoint(new GeoCoordinate(48.976, 2.49162)));
    // calculate a route for navigation
    CoreRouter coreRouter = new CoreRouter();
    coreRouter.calculateRoute(routePlan, new CoreRouter.Listener() {

        @Override
        public void onCalculateRouteFinished(List<RouteResult> list, RoutingError routingError) {
            if (routingError == RoutingError.NONE) {
                Route route = list.get(0).getRoute();
                m_currentRoute = new MapRoute(route);
                m_map.addMapObject(m_currentRoute);
                // move the map to the first waypoint which is starting point of
                // the route
                m_map.setCenter(routePlan.getWaypoint(0).getNavigablePosition(), Map.Animation.NONE);
                // setting MapUpdateMode to RoadView will enable automatic map
                // movements and zoom level adjustments
                NavigationManager navigationManager = NavigationManager.getInstance();
                navigationManager.setMapUpdateMode(NavigationManager.MapUpdateMode.ROADVIEW);
                // adjust tilt to show 3D view
                m_map.setTilt(80);
                // adjust transform center for navigation experience in portrait
                // view
                m_mapTransformCenter = new PointF(m_map.getTransformCenter().x, (m_map.getTransformCenter().y * 85 / 50));
                m_map.setTransformCenter(m_mapTransformCenter);
                // create a map marker to show current position
                Image icon = new Image();
                m_positionIndicatorFixed = new MapMarker();
                try {
                    icon.setImageResource(R.drawable.gps_position);
                    m_positionIndicatorFixed.setIcon(icon);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                m_positionIndicatorFixed.setVisible(true);
                m_positionIndicatorFixed.setCoordinate(m_map.getCenter());
                m_map.addMapObject(m_positionIndicatorFixed);
                m_mapFragment.getPositionIndicator().setVisible(false);
                navigationManager.setMap(m_map);
                // listen to real position updates. This is used when RoadView is
                // not active.
                PositioningManager.getInstance().addListener(new WeakReference<>(mapPositionHandler));
                // listen to updates from RoadView which tells you where the map
                // center should be situated. This is used when RoadView is active.
                navigationManager.getRoadView().addListener(new WeakReference<>(roadViewListener));
                // listen to navigation manager events.
                navigationManager.addNavigationManagerEventListener(new WeakReference<>(navigationManagerEventListener));
                navigationManager.addLaneInformationListener(new WeakReference<>(m_laneInformationListener));
                // start navigation simulation travelling at 13 meters per second
                navigationManager.simulate(route, 13);
            } else {
                Toast.makeText(m_activity, "Error:route calculation returned error code: " + routingError, Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onProgress(int i) {
        }
    });
}
Also used : MapRoute(com.here.android.mpa.mapping.MapRoute) NavigationManager(com.here.android.mpa.guidance.NavigationManager) MapMarker(com.here.android.mpa.mapping.MapMarker) PointF(android.graphics.PointF) CoreRouter(com.here.android.mpa.routing.CoreRouter) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) IOException(java.io.IOException) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) Image(com.here.android.mpa.common.Image) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) RoutingError(com.here.android.mpa.routing.RoutingError) RouteResult(com.here.android.mpa.routing.RouteResult) WeakReference(java.lang.ref.WeakReference) RoutePlan(com.here.android.mpa.routing.RoutePlan) Route(com.here.android.mpa.routing.Route) MapRoute(com.here.android.mpa.mapping.MapRoute)

Example 3 with Image

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

the class MapFragmentView method addMarkerAtPlace.

// Place markers handling helpers
private void addMarkerAtPlace(PlaceLink placeLink) {
    Image img = new Image();
    try {
        img.setImageResource(R.drawable.marker);
    } catch (IOException e) {
        e.printStackTrace();
    }
    MapMarker mapMarker = new MapMarker();
    mapMarker.setIcon(img);
    mapMarker.setCoordinate(new GeoCoordinate(placeLink.getPosition()));
    Map map = m_mapFragment.getMap();
    map.addMapObject(mapMarker);
    m_mapObjectList.add(mapMarker);
}
Also used : MapMarker(com.here.android.mpa.mapping.MapMarker) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) IOException(java.io.IOException) Image(com.here.android.mpa.common.Image) Map(com.here.android.mpa.mapping.Map)

Example 4 with Image

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

the class MapFragmentView method addMapMarkerObject.

/**
 * create a MapMarker and add the MapMarker to active map view.
 */
private void addMapMarkerObject() {
    // create an image from cafe.png.
    Image marker_img = new Image();
    try {
        marker_img.setImageResource(R.drawable.cafe);
    } catch (IOException e) {
        e.printStackTrace();
    }
    // create a MapMarker centered at current location with png image.
    MapMarker marker = new MapMarker(m_map.getCenter(), marker_img);
    /*
         * Set MapMarker draggable.
         * How to move to?
         * In order to activate dragging of the MapMarker you have to do a long press on
         * the MapMarker then move it to a new position and release the MapMarker.
         */
    marker.setDraggable(true);
    marker.setTitle("MapMarker id: " + mapMarkerCount++);
    // add a MapMarker to current active map.
    m_map.addMapObject(marker);
    m_map_markers.add(marker);
}
Also used : MapMarker(com.here.android.mpa.mapping.MapMarker) IOException(java.io.IOException) Image(com.here.android.mpa.common.Image)

Example 5 with Image

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

the class MapFragmentView method showCapitals.

/**
 * Method contains logic for extracting data about capitals and placing it on a map
 */
private void showCapitals() {
    /*
         * Create an image for marker
         */
    final int[] colorArray = new int[25 * 25];
    for (int i = 0; i < colorArray.length; i++) {
        colorArray[i] = Color.GREEN;
    }
    Bitmap bitmap = Bitmap.createBitmap(colorArray, 25, 25, Bitmap.Config.ARGB_8888);
    final Image image = new Image();
    image.setBitmap(bitmap);
    /*
         * Create list of PDE layers to extract
         */
    Set<String> layers = new HashSet<>(Arrays.asList(CITY_POI_LAYER));
    GeoBoundingBox bbox = map.getBoundingBox();
    /*
         * Check that bounding box is valid
         */
    if (bbox == null || bbox.isEmpty()) {
        Log.e(TAG, "PDE bbox is null or empty!");
        Toast.makeText(this.activity.getApplicationContext(), "Current zoom level is too low. Please zoom closer.", Toast.LENGTH_LONG).show();
    } else {
        /*
             * Create and send PDE request
             */
        final PlatformDataRequest request = PlatformDataRequest.createBoundingBoxRequest(layers, bbox);
        request.execute(new PlatformDataRequest.Listener<PlatformDataResult>() {

            @Override
            public void onCompleted(PlatformDataResult platformDataResult, PlatformDataRequest.Error error) {
                if (error == null) {
                    /*
                         * Process PDE request response
                         */
                    PlatformDataItemCollection result = platformDataResult.get(CITY_POI_LAYER);
                    List<MapObject> markers = new ArrayList<>();
                    for (java.util.Map<String, String> entry : result.extract()) {
                        double lat = Double.parseDouble(entry.get("LAT")) / 100_000;
                        double lon = Double.parseDouble(entry.get("LON")) / 100_000;
                        MapMarker marker = new MapMarker();
                        marker.setCoordinate(new GeoCoordinate(lat, lon));
                        marker.setIcon(image);
                        markers.add(marker);
                    }
                    /*
                         * Add list of map markers on map
                         */
                    map.addMapObjects(markers);
                    /*
                         * Set the zoom level.
                         */
                    map.setZoomLevel(3.95);
                } 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());
                }
            }
        });
    }
}
Also used : MapMarker(com.here.android.mpa.mapping.MapMarker) PlatformDataItemCollection(com.here.android.mpa.pde.PlatformDataItemCollection) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) Image(com.here.android.mpa.common.Image) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) Bitmap(android.graphics.Bitmap) PlatformDataRequest(com.here.android.mpa.pde.PlatformDataRequest) PlatformDataResult(com.here.android.mpa.pde.PlatformDataResult) ArrayList(java.util.ArrayList) List(java.util.List) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox) HashMap(java.util.HashMap) Map(com.here.android.mpa.mapping.Map) HashSet(java.util.HashSet)

Aggregations

Image (com.here.android.mpa.common.Image)7 MapMarker (com.here.android.mpa.mapping.MapMarker)6 IOException (java.io.IOException)6 GeoCoordinate (com.here.android.mpa.common.GeoCoordinate)4 PointF (android.graphics.PointF)2 Map (com.here.android.mpa.mapping.Map)2 RouteWaypoint (com.here.android.mpa.routing.RouteWaypoint)2 List (java.util.List)2 DialogInterface (android.content.DialogInterface)1 Bitmap (android.graphics.Bitmap)1 GeoBoundingBox (com.here.android.mpa.common.GeoBoundingBox)1 OnEngineInitListener (com.here.android.mpa.common.OnEngineInitListener)1 NavigationManager (com.here.android.mpa.guidance.NavigationManager)1 MapRoute (com.here.android.mpa.mapping.MapRoute)1 MapScreenMarker (com.here.android.mpa.mapping.MapScreenMarker)1 PlatformDataItemCollection (com.here.android.mpa.pde.PlatformDataItemCollection)1 PlatformDataRequest (com.here.android.mpa.pde.PlatformDataRequest)1 PlatformDataResult (com.here.android.mpa.pde.PlatformDataResult)1 CoreRouter (com.here.android.mpa.routing.CoreRouter)1 Route (com.here.android.mpa.routing.Route)1