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);
}
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);
}
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);
}
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);
}
}
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());
}
}
});
}
}
Aggregations