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