use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.
the class MainView method triggerRevGeocodeRequest.
private void triggerRevGeocodeRequest() {
m_resultTextView.setText("");
/* Create a ReverseGeocodeRequest object with a GeoCoordinate. */
GeoCoordinate coordinate = new GeoCoordinate(49.25914, -123.00777);
ReverseGeocodeRequest revGecodeRequest = new ReverseGeocodeRequest(coordinate);
revGecodeRequest.execute(new ResultListener<Location>() {
@Override
public void onCompleted(Location location, ErrorCode errorCode) {
if (errorCode == ErrorCode.NONE) {
/*
* From the location object, we retrieve the address and display to the screen.
* Please refer to HERE Android SDK doc for other supported APIs.
*/
updateTextView(location.getAddress().toString());
} else {
updateTextView("ERROR:RevGeocode Request returned error code:" + errorCode);
}
}
});
}
use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.
the class MapFragmentView method initMapFragment.
private void initMapFragment() {
/* Locate the mapFragment UI element */
m_mapFragment = getMapFragment();
// This will use external storage to save map cache data, it is also possible to set
// private app's path
String path = new File(m_activity.getExternalFilesDir(null), ".here-map-data").getAbsolutePath();
// This method will throw IllegalArgumentException if provided path is not writable
com.here.android.mpa.common.MapSettings.setDiskCacheRootPath(path);
if (m_mapFragment != null) {
/* Initialize the AndroidXMapFragment, results will be given via the called back. */
m_mapFragment.init(new OnEngineInitListener() {
@Override
public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
if (error == Error.NONE) {
/*
* If no error returned from map fragment initialization, the map will be
* rendered on screen at this moment.Further actions on map can be provided
* by calling Map APIs.
*/
m_map = m_mapFragment.getMap();
/*
* Set the map center to the 4350 Still Creek Dr Burnaby BC (no animation).
*/
m_map.setCenter(new GeoCoordinate(49.259149, -123.008555, 0.0), Map.Animation.NONE);
/* Set the zoom level to the average between min and max zoom level. */
m_map.setZoomLevel(14);
m_activity.supportInvalidateOptionsMenu();
/*
* Set up a handler for handling MapMarker drag events.
*/
m_mapFragment.setMapMarkerDragListener(new OnDragListenerHandler());
} else {
Log.e(this.getClass().toString(), "onEngineInitializationCompleted: " + "ERROR=" + error.getDetails(), error.getThrowable());
new AlertDialog.Builder(m_activity).setMessage("Error : " + error.name() + "\n\n" + error.getDetails()).setTitle(R.string.engine_init_error).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
m_activity.finish();
}
}).create().show();
}
}
});
}
}
use of com.here.android.mpa.common.GeoCoordinate 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.GeoCoordinate 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.GeoCoordinate 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);
}
Aggregations