use of com.here.android.mpa.common.PositioningManager in project here-android-sdk-examples by heremaps.
the class PositioningService method initMapEngine.
/**
* Initialize HERE SDK map engine.
*/
private void initMapEngine() {
if (MapEngine.isInitialized()) {
return;
}
final MapEngine engine = MapEngine.getInstance();
engine.init(new ApplicationContext(getApplicationContext()), new OnEngineInitListener() {
@Override
public void onEngineInitializationCompleted(Error error) {
if (error == OnEngineInitListener.Error.NONE) {
mNotificationUtils.updateNotification(R.drawable.ic_paused, R.string.notificationTitle, R.string.notificationMapEngineReady);
if (mListener != null) {
try {
mListener.onEngineIntialized();
} catch (RemoteException ex) {
// ignored
}
}
final PositioningManager posManager = PositioningManager.getInstance();
final LocationDataSource hereLocation = LocationDataSourceHERE.getInstance();
if (hereLocation == null) {
Log.e(TAG, "initMapEngine: failed to instantiate HERE location");
return;
}
posManager.setDataSource(hereLocation);
} else {
Log.e(TAG, "initMapEngine: MapEngine.init failed: " + error.getDetails());
}
}
});
}
use of com.here.android.mpa.common.PositioningManager in project here-android-sdk-examples by heremaps.
the class Venue3dActivity method initialize.
private void initialize() {
setContentView(R.layout.venues3d);
m_activity = this;
// Search for the map fragment in order to finish setup by calling init().
m_mapFragment = getMapFragment();
m_venueIdEditText = (EditText) findViewById(R.id.venueIdEditText);
m_mainControlLayout = (LinearLayout) findViewById(R.id.venueOpeningLayout);
m_routeInfoLayout = (LinearLayout) findViewById(R.id.routeInfoLayout);
m_routingOptionType = (Spinner) findViewById(R.id.routeOptionType);
m_routingOptionMode = (Spinner) findViewById(R.id.routeOptionMode);
m_routeStartGuideText = (TextView) findViewById(R.id.startLocationGuideText);
m_routeEndGuideText = (TextView) findViewById(R.id.endLocationGuideText);
m_routingFromText = (TextView) findViewById(R.id.startLocationText);
m_routingToText = (TextView) findViewById(R.id.endLocationText);
m_showRouteButton = (Button) findViewById(R.id.buttonShowRoute);
// Fill dropDownList with routing type names.
String[] type_values = new String[] { "Fastest", "Shortest" };
configureSpinner(m_routingOptionType, type_values);
// Fill dropDownList with routing mode names.
String[] mode_values = new String[] { "Car", "Pedestrian", "Public Transport" };
configureSpinner(m_routingOptionMode, mode_values);
// Set default values to: Fastest and Pedestrian.
m_routingOptionType.setSelection(0);
m_routingOptionMode.setSelection(1);
// Set path of disk cache
String diskCacheRoot = m_activity.getFilesDir().getPath() + File.separator + ".isolated-here-maps";
// This will use external storage to save map cache data, it is also possible to set
// private app's path
String path = new File(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);
// Initialise the Map Fragment to have a map created and attached to
// the fragment
m_mapFragment.init(new OnEngineInitListener() {
@Override
public void onEngineInitializationCompleted(Error error) {
if (error == Error.NONE) {
// retrieve a reference of the map from the map fragment
m_map = m_mapFragment.getMap();
// Set the map center, zoom level, orientation and tilt
m_map.setCenter(new GeoCoordinate(49.196261, -123.004773, 0.0), Map.Animation.NONE);
} else {
System.out.println("ERROR: Cannot initialize Map Fragment" + error.toString());
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();
}
}
}, new VenueServiceListener() {
@Override
public void onInitializationCompleted(InitStatus result) {
if (result == InitStatus.ONLINE_SUCCESS || result == InitStatus.OFFLINE_SUCCESS) {
// Register the activity class as VenueMapFragment.VenueListener
m_mapFragment.addListener(m_activity);
// Set animations on for floor change and venue entering
m_mapFragment.setFloorChangingAnimation(true);
m_mapFragment.setVenueEnteringAnimation(true);
// Ask notification when venue visible; this notification is
// part of VenueMapFragment.VenueListener
m_mapFragment.setVenuesInViewportCallback(true);
// Add listener for onCombinedRouteCompleted.
m_mapFragment.getRoutingController().addListener(m_activity);
// Add listener for map gesture.
m_mapFragment.getMapGesture().addOnGestureListener(m_activity, 0, false);
// Create floor change widget
m_floorsController = new VenueFloorsController(m_activity, m_mapFragment, (ListView) findViewById(R.id.floorListView), R.layout.floor_item, R.id.floorName, R.id.floorGroundSep);
m_initCompleted.set(true);
// Start position tracking
PositioningManager positioningManager = PositioningManager.getInstance();
positioningManager.start(PositioningManager.LocationMethod.GPS_NETWORK_INDOOR);
// Set positioning indicator visible
PositionIndicator positionIndicator = m_mapFragment.getPositionIndicator();
positionIndicator.setVisible(true);
}
}
});
}
use of com.here.android.mpa.common.PositioningManager in project here-android-sdk-examples by heremaps.
the class BackgroundPositioningActivity method updateButtons.
/**
* Update UI buttons based on positioning service state.
*/
private void updateButtons() {
if (mTogglePositioning == null) {
return;
}
mTogglePositioning.setEnabled(false);
if (mController == null) {
mTogglePositioning.setChecked(false);
return;
}
if (!MapEngine.isInitialized()) {
return;
}
mTogglePositioning.setEnabled(true);
final PositioningManager posManager = PositioningManager.getInstance();
if (posManager == null) {
return;
}
mTogglePositioning.setChecked(posManager.isActive());
}
use of com.here.android.mpa.common.PositioningManager in project here-android-sdk-examples by heremaps.
the class PositioningService method onBind.
@Nullable
@Override
public IBinder onBind(Intent intent) {
if (ACTION_GET_API.equals(intent.getAction())) {
return new IPositioningServiceControl.Stub() {
@Override
public void setListener(IPositioningServiceListener listener) throws RemoteException {
mListener = listener;
if (mListener == null) {
throw new IllegalArgumentException("listener cannot be null");
}
if (MapEngine.isInitialized()) {
try {
mListener.onEngineIntialized();
} catch (RemoteException ex) {
Log.e(TAG, ex.getMessage());
}
}
}
@Override
public void startBackground() throws RemoteException {
final PositioningManager posManager = PositioningManager.getInstance();
if (posManager != null) {
if (posManager.start(PositioningManager.LocationMethod.GPS_NETWORK)) {
mNotificationUtils.updateNotification(R.drawable.ic_playing, R.string.notificationTitle, R.string.notificationBgPositioningStarted);
}
}
}
@Override
public void stopBackground() throws RemoteException {
final PositioningManager posManager = PositioningManager.getInstance();
if (posManager != null) {
posManager.stop();
mNotificationUtils.updateNotification(R.drawable.ic_paused, R.string.notificationTitle, R.string.notificationMapEngineReady);
}
mListener = null;
}
};
}
return null;
}
Aggregations