Search in sources :

Example 6 with GeoBoundingBox

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

the class MapFragmentView method addPolylineObject.

/**
 * Create a MapPolyline and add the MapPolyline to active map view.
 */
private void addPolylineObject() {
    // 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);
    MapPolyline polyline = new MapPolyline(geoPolyline);
    polyline.setLineColor(Color.BLUE);
    polyline.setLineWidth(12);
    // add GeoPolyline to current active map
    m_map.addMapObject(polyline);
    m_polylines.add(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 7 with GeoBoundingBox

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

the class MapFragmentView method navigateToMapMarkers.

private void navigateToMapMarkers(List<MapMarker> markers, int padding) {
    // find max and min latitudes and longitudes in order to calculate
    // geo bounding box so then we can map.zoomTo(geoBox, ...) to it.
    double minLat = 90.0d;
    double minLon = 180.0d;
    double maxLat = -90.0d;
    double maxLon = -180.0d;
    for (MapMarker marker : markers) {
        GeoCoordinate coordinate = marker.getCoordinate();
        double latitude = coordinate.getLatitude();
        double longitude = coordinate.getLongitude();
        minLat = Math.min(minLat, latitude);
        minLon = Math.min(minLon, longitude);
        maxLat = Math.max(maxLat, latitude);
        maxLon = Math.max(maxLon, longitude);
    }
    GeoBoundingBox box = new GeoBoundingBox(new GeoCoordinate(maxLat, minLon), new GeoCoordinate(minLat, maxLon));
    ViewRect viewRect = new ViewRect(padding, padding, m_map.getWidth() - padding * 2, m_map.getHeight() - padding * 2);
    m_map.zoomTo(box, viewRect, Map.Animation.LINEAR, Map.MOVE_PRESERVE_ORIENTATION);
}
Also used : MapMarker(com.here.android.mpa.mapping.MapMarker) ViewRect(com.here.android.mpa.common.ViewRect) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox)

Example 8 with GeoBoundingBox

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

the class MapFragmentView method addPolygonObject.

/**
 * Create a MapPolygon and add the MapPolygon to active map view.
 */
private void addPolygonObject() {
    // 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.
    MapPolygon polygon = new MapPolygon(geoPolygon);
    // set line color, fill color and line width
    polygon.setLineColor(Color.RED);
    polygon.setFillColor(Color.GRAY);
    polygon.setLineWidth(12);
    // add MapPolygon to map.
    m_map.addMapObject(polygon);
    m_polygons.add(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 9 with GeoBoundingBox

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

the class MapFragmentView method prefetchMap.

private void prefetchMap(OptionType selectedOption) {
    m_mapDataPrefetcher = MapDataPrefetcher.getInstance();
    m_mapDataPrefetcher.addListener(new PrefetchMapDataListener());
    changeState(State.DEFAULT);
    MapDataPrefetcher.Request prefetchRequest;
    if (selectedOption == OptionType.MAP_BOUNDING_BOX) {
        GeoCoordinate m_geoCoordinate = new GeoCoordinate(53.34187, -6.28635);
        m_geoBoundingBox = new GeoBoundingBox(m_geoCoordinate, BOUNDING_BOX_HEIGHT, BOUNDING_BOX_WIDTH);
        m_mapDataPrefetcher.estimateMapDataSize(m_geoBoundingBox);
        prefetchRequest = m_mapDataPrefetcher.fetchMapData(m_geoBoundingBox);
    } else {
        m_mapDataPrefetcher.estimateMapDataSize(m_route, ROUTE_RADIUS);
        prefetchRequest = m_mapDataPrefetcher.fetchMapData(m_route, ROUTE_RADIUS);
    }
}
Also used : MapDataPrefetcher(com.here.android.mpa.prefetcher.MapDataPrefetcher) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox)

Example 10 with GeoBoundingBox

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

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