use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.
the class BackgroundPositioningActivity method updateLocationInfo.
/**
* Update location information.
* @param geoPosition Latest geo position update.
*/
private void updateLocationInfo(PositioningManager.LocationMethod locationMethod, GeoPosition geoPosition) {
if (mLocationInfo == null) {
return;
}
final StringBuffer sb = new StringBuffer();
final GeoCoordinate coord = geoPosition.getCoordinate();
sb.append("Type: ").append(String.format(Locale.US, "%s\n", locationMethod.name()));
sb.append("Coordinate:").append(String.format(Locale.US, "%.6f, %.6f\n", coord.getLatitude(), coord.getLongitude()));
if (coord.getAltitude() != GeoCoordinate.UNKNOWN_ALTITUDE) {
sb.append("Altitude:").append(String.format(Locale.US, "%.2fm\n", coord.getAltitude()));
}
if (geoPosition.getHeading() != GeoPosition.UNKNOWN) {
sb.append("Heading:").append(String.format(Locale.US, "%.2f\n", geoPosition.getHeading()));
}
if (geoPosition.getSpeed() != GeoPosition.UNKNOWN) {
sb.append("Speed:").append(String.format(Locale.US, "%.2fm/s\n", geoPosition.getSpeed()));
}
if (geoPosition.getBuildingName() != null) {
sb.append("Building: ").append(geoPosition.getBuildingName());
if (geoPosition.getBuildingId() != null) {
sb.append(" (").append(geoPosition.getBuildingId()).append(")\n");
} else {
sb.append("\n");
}
}
if (geoPosition.getFloorId() != null) {
sb.append("Floor: ").append(geoPosition.getFloorId()).append("\n");
}
sb.deleteCharAt(sb.length() - 1);
mLocationInfo.setText(sb.toString());
}
use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.
the class BasicVenueActivity method startVenueMaps.
/**
* Initializes HERE Venue Maps. Called after permission check.
*/
private void startVenueMaps() {
Log.v(TAG, "InitializeVenueMaps");
mActivity = this;
mVenueMapFragment = getMapFragment();
mLocationInfo = (TextView) findViewById(R.id.textViewLocationInfo);
mVenueMapFragment.init(new OnEngineInitListener() {
@Override
public void onEngineInitializationCompleted(Error error) {
if (error == Error.NONE) {
Log.v(TAG, "InitializeVenueMaps: OnEngineInitializationCompleted");
mVenueService = mVenueMapFragment.getVenueService();
mRoutingController = mVenueMapFragment.getRoutingController();
if (mRoutingController != null) {
mRoutingController.addListener(BasicVenueActivity.this);
}
// Setting venue service content based on menu option
if (!mPrivateVenues) {
// Public only
setVenueServiceContent(false, false);
} else {
// Private + public
setVenueServiceContent(true, true);
}
} else {
new AlertDialog.Builder(BasicVenueActivity.this).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) {
BasicVenueActivity.this.finish();
}
}).create().show();
}
}
}, new VenueServiceListener() {
@Override
public void onInitializationCompleted(VenueService.InitStatus result) {
Log.v(TAG, "VenueServiceListener: OnInitializationCompleted with result: %s", result);
switch(result) {
case IN_PROGRESS:
Log.v(TAG, "Initialization of venue service is in progress...");
Toast.makeText(BasicVenueActivity.this, "Initialization of venue service is in progress...", Toast.LENGTH_SHORT).show();
break;
case OFFLINE_SUCCESS:
case ONLINE_SUCCESS:
// Adding venue listener to map fragment
mVenueMapFragment.addListener(mActivity);
// Set animations on for floor change and venue entering
mVenueMapFragment.setFloorChangingAnimation(true);
mVenueMapFragment.setVenueEnteringAnimation(true);
// Ask notification when venue visible; this notification is
// part of VenueMapFragment.VenueListener
mVenueMapFragment.setVenuesInViewportCallback(true);
// Add Gesture Listener for map fragment
mVenueMapFragment.getMapGesture().addOnGestureListener(mActivity, 0, false);
// retrieve a reference of the map from the map fragment
mMap = mVenueMapFragment.getMap();
mMap.addTransformListener(mActivity);
mMap.setZoomLevel(mMap.getMaxZoomLevel() - 3);
// Create floors controller widget
mFloorsControllerWidget = new FloorsControllerWidget(mActivity, mVenueMapFragment, (ListView) findViewById(R.id.floorListView), R.layout.floor_item, R.id.floorName, R.id.floorGroundSep);
// Start of Position Updates
try {
startPositionUpdates();
mVenueMapFragment.getPositionIndicator().setVisible(true);
} catch (Exception ex) {
Log.w(TAG, "startPositionUpdates: Could not register for location updates: %s", Log.getStackTraceString(ex));
}
if (mLastMapCenter == null) {
mMap.setCenter(new GeoCoordinate(61.497961, 23.763606, 0.0), Map.Animation.NONE);
} else {
mMap.setCenter(mLastMapCenter, Map.Animation.NONE);
}
break;
}
}
});
}
use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.
the class BasicPositioningActivity method initializeMapsAndPositioning.
/**
* Initializes HERE Maps and HERE Positioning. Called after permission check.
*/
private void initializeMapsAndPositioning() {
setContentView(R.layout.activity_main);
mLocationInfo = (TextView) findViewById(R.id.textViewLocationInfo);
mapFragment = getMapFragment();
mapFragment.setRetainInstance(false);
mapFragment.init(new OnEngineInitListener() {
@Override
public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
if (error == OnEngineInitListener.Error.NONE) {
map = mapFragment.getMap();
map.setCenter(new GeoCoordinate(61.497961, 23.763606, 0.0), Map.Animation.NONE);
map.setZoomLevel(map.getMaxZoomLevel() - 1);
map.addTransformListener(BasicPositioningActivity.this);
mPositioningManager = PositioningManager.getInstance();
mHereLocation = LocationDataSourceHERE.getInstance(new StatusListener() {
@Override
public void onOfflineModeChanged(boolean offline) {
// called when offline mode changes
}
@Override
public void onAirplaneModeEnabled() {
// called when airplane mode is enabled
}
@Override
public void onWifiScansDisabled() {
// called when Wi-Fi scans are disabled
}
@Override
public void onBluetoothDisabled() {
// called when Bluetooth is disabled
}
@Override
public void onCellDisabled() {
// called when Cell radios are switch off
}
@Override
public void onGnssLocationDisabled() {
// called when GPS positioning is disabled
}
@Override
public void onNetworkLocationDisabled() {
// called when network positioning is disabled
}
@Override
public void onServiceError(ServiceError serviceError) {
// called on HERE service error
}
@Override
public void onPositioningError(PositioningError positioningError) {
// called when positioning fails
}
@Override
@SuppressWarnings("deprecation")
public void onWifiIndoorPositioningNotAvailable() {
// called when running on Android 9.0 (Pie) or newer
}
@Override
public void onWifiIndoorPositioningDegraded() {
// called when running on Android 9.0 (Pie) or newer
}
});
if (mHereLocation == null) {
Toast.makeText(BasicPositioningActivity.this, "LocationDataSourceHERE.getInstance(): failed, exiting", Toast.LENGTH_LONG).show();
finish();
}
mPositioningManager.setDataSource(mHereLocation);
mPositioningManager.addListener(new WeakReference<PositioningManager.OnPositionChangedListener>(BasicPositioningActivity.this));
// start position updates, accepting GPS, network or indoor positions
if (mPositioningManager.start(PositioningManager.LocationMethod.GPS_NETWORK_INDOOR)) {
mapFragment.getPositionIndicator().setVisible(true);
} else {
Toast.makeText(BasicPositioningActivity.this, "PositioningManager.start: failed, exiting", Toast.LENGTH_LONG).show();
finish();
}
} else {
new AlertDialog.Builder(BasicPositioningActivity.this).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) {
finish();
}
}).create().show();
}
}
});
}
use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.
the class RouteUtil method createRoute.
public static RoutePlan createRoute() {
/* Initialize a RoutePlan */
final RoutePlan routePlan = new RoutePlan();
/*
* Initialize a RouteOption. HERE Mobile SDK allow users to define their own parameters for the
* route calculation,including transport modes,route types and route restrictions etc.Please
* refer to API doc for full list of APIs
*/
final RouteOptions routeOptions = new RouteOptions();
/* Other transport modes are also available e.g Pedestrian */
routeOptions.setTransportMode(RouteOptions.TransportMode.CAR);
/* Disable highway in this route. */
routeOptions.setHighwaysAllowed(false);
/* Calculate the shortest route available. */
routeOptions.setRouteType(RouteOptions.Type.FASTEST);
/* Calculate 1 route. */
routeOptions.setRouteCount(1);
/* Finally set the route option */
routePlan.setRouteOptions(routeOptions);
/* Define waypoints for the route */
/* START: Holländerstraße, Wedding, 13407 Berlin */
RouteWaypoint startPoint = new RouteWaypoint(new GeoCoordinate(52.562755700200796, 13.34599438123405));
/* MIDDLE: Lynarstraße 3 */
RouteWaypoint middlePoint = new RouteWaypoint(new GeoCoordinate(52.54172, 13.36354));
/* END: Agricolastraße 29, 10555 Berlin */
RouteWaypoint destination = new RouteWaypoint(new GeoCoordinate(52.520720371976495, 13.332345457747579));
/* Add both waypoints to the route plan */
routePlan.addWaypoint(startPoint);
routePlan.addWaypoint(middlePoint);
routePlan.addWaypoint(destination);
return routePlan;
}
use of com.here.android.mpa.common.GeoCoordinate in project here-android-sdk-examples by heremaps.
the class MapFragmentView method createRoute.
private void createRoute() {
/* Initialize a CoreRouter */
CoreRouter coreRouter = new CoreRouter();
/* Initialize a RoutePlan */
RoutePlan routePlan = new RoutePlan();
/*
* Initialize a RouteOption. HERE Mobile SDK allow users to define their own parameters for the
* route calculation,including transport modes,route types and route restrictions etc.Please
* refer to API doc for full list of APIs
*/
RouteOptions routeOptions = new RouteOptions();
/* Other transport modes are also available e.g Pedestrian */
routeOptions.setTransportMode(RouteOptions.TransportMode.CAR);
/* Disable highway in this route. */
routeOptions.setHighwaysAllowed(false);
/* Calculate the shortest route available. */
routeOptions.setRouteType(RouteOptions.Type.SHORTEST);
/* Calculate 1 route. */
routeOptions.setRouteCount(1);
/* Finally set the route option */
routePlan.setRouteOptions(routeOptions);
/* Define waypoints for the route */
/* START: 4350 Still Creek Dr */
RouteWaypoint startPoint = new RouteWaypoint(new GeoCoordinate(49.259149, -123.008555));
/* END: Langley BC */
RouteWaypoint destination = new RouteWaypoint(new GeoCoordinate(49.073640, -122.559549));
/* Add both waypoints to the route plan */
routePlan.addWaypoint(startPoint);
routePlan.addWaypoint(destination);
/* Trigger the route calculation,results will be called back via the listener */
coreRouter.calculateRoute(routePlan, new Router.Listener<List<RouteResult>, RoutingError>() {
@Override
public void onProgress(int i) {
/* The calculation progress can be retrieved in this callback. */
}
@Override
public void onCalculateRouteFinished(List<RouteResult> routeResults, RoutingError routingError) {
/* Calculation is done.Let's handle the result */
if (routingError == RoutingError.NONE) {
if (routeResults.get(0).getRoute() != null) {
m_route = routeResults.get(0).getRoute();
/* Create a MapRoute so that it can be placed on the map */
MapRoute mapRoute = new MapRoute(routeResults.get(0).getRoute());
/* Show the maneuver number on top of the route */
mapRoute.setManeuverNumberVisible(true);
/* Add the MapRoute to the map */
m_map.addMapObject(mapRoute);
/*
* We may also want to make sure the map view is orientated properly
* so the entire route can be easily seen.
*/
m_geoBoundingBox = routeResults.get(0).getRoute().getBoundingBox();
m_map.zoomTo(m_geoBoundingBox, Map.Animation.NONE, Map.MOVE_PRESERVE_ORIENTATION);
startNavigation();
} else {
Toast.makeText(m_activity, "Error:route results returned is not valid", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(m_activity, "Error:route calculation returned error code: " + routingError, Toast.LENGTH_LONG).show();
}
}
});
}
Aggregations