Search in sources :

Example 11 with MapMarker

use of com.here.android.mpa.mapping.MapMarker 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 12 with MapMarker

use of com.here.android.mpa.mapping.MapMarker 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)

Example 13 with MapMarker

use of com.here.android.mpa.mapping.MapMarker in project here-android-sdk-examples by heremaps.

the class MapFragmentView method addMarkerAtPlace.

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()));
    m_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)

Aggregations

MapMarker (com.here.android.mpa.mapping.MapMarker)13 GeoCoordinate (com.here.android.mpa.common.GeoCoordinate)7 Image (com.here.android.mpa.common.Image)6 IOException (java.io.IOException)5 CLE2PointGeometry (com.here.android.mpa.customlocation2.CLE2PointGeometry)3 RouteWaypoint (com.here.android.mpa.routing.RouteWaypoint)3 PointF (android.graphics.PointF)2 GeoBoundingBox (com.here.android.mpa.common.GeoBoundingBox)2 CLE2Geometry (com.here.android.mpa.customlocation2.CLE2Geometry)2 CLE2Request (com.here.android.mpa.customlocation2.CLE2Request)2 NavigationManager (com.here.android.mpa.guidance.NavigationManager)2 Map (com.here.android.mpa.mapping.Map)2 CoreRouter (com.here.android.mpa.routing.CoreRouter)2 RoutePlan (com.here.android.mpa.routing.RoutePlan)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Bitmap (android.graphics.Bitmap)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 GeoPolyline (com.here.android.mpa.common.GeoPolyline)1