[location] Refactoring of native -> cross platform passing location parameters.

This commit is contained in:
vng 2014-09-26 14:44:57 +03:00 committed by Alex Zolotarev
parent 010c86d543
commit 163a69a515
18 changed files with 256 additions and 170 deletions

View file

@ -70,14 +70,8 @@ namespace android
Platform::RunOnGuiThreadImpl(bind(&::Framework::OnLocationUpdate, ref(m_work), info));
}
void Framework::OnCompassUpdated(uint64_t timestamp, double magneticNorth, double trueNorth, double accuracy)
void Framework::OnCompassUpdated(location::CompassInfo const & info)
{
location::CompassInfo info;
info.m_timestamp = static_cast<double>(timestamp);
info.m_magneticHeading = magneticNorth;
info.m_trueHeading = trueNorth;
info.m_accuracy = accuracy;
Platform::RunOnGuiThreadImpl(bind(&::Framework::OnCompassUpdate, ref(m_work), info));
}
@ -1129,6 +1123,30 @@ extern "C"
g_framework->NativeFramework()->StartRoutingSession(MercatorBounds::FromLatLon(lat, lon));
}
JNIEXPORT jobject JNICALL
Java_com_mapswithme_maps_Framework_nativeGetRouteFollowingInfo(JNIEnv * env, jclass thiz)
{
::Framework * frm = g_framework->NativeFramework();
if (frm->IsRoutingActive())
{
location::FollowingInfo info;
frm->GetRouteFollowingInfo(info);
if (info.IsValid())
{
jclass klass = env->FindClass("com/mapswithme/maps/LocationState$RoutingInfo");
jmethodID methodID = env->GetMethodID(klass, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");
return env->NewObject(klass, methodID,
jni::ToJavaString(env, info.m_distToTarget),
jni::ToJavaString(env, info.m_unitsSuffix));
}
}
return 0;
}
JNIEXPORT jobject JNICALL
Java_com_mapswithme_maps_Framework_nativeGetMapObjectForPoint(JNIEnv * env, jclass clazz, jdouble lat, jdouble lon)
{
@ -1136,14 +1154,13 @@ extern "C"
g_framework->NativeFramework()->GetAddressInfoForGlobalPoint(MercatorBounds::FromLatLon(lat, lon), info);
jclass objClazz = env->FindClass("com/mapswithme/maps/bookmarks/data/MapObject$Poi");
jmethodID methodID = env->GetMethodID(objClazz,
"<init>", "(Ljava/lang/String;DDLjava/lang/String;)V");
jclass klass = env->FindClass("com/mapswithme/maps/bookmarks/data/MapObject$Poi");
jmethodID methodID = env->GetMethodID(klass, "<init>", "(Ljava/lang/String;DDLjava/lang/String;)V");
const jstring j_name = jni::ToJavaString(env, info.GetPinName());
const jstring j_type = jni::ToJavaString(env, info.GetPinType());
return env->NewObject(objClazz, methodID, j_name, lat, lon, j_type);
return env->NewObject(klass, methodID,
jni::ToJavaString(env, info.GetPinName()),
lat, lon,
jni::ToJavaString(env, info.GetPinType()));
}
JNIEXPORT void JNICALL

View file

@ -71,7 +71,7 @@ namespace android
void OnLocationError(int/* == location::TLocationStatus*/ newStatus);
void OnLocationUpdated(location::GpsInfo const & info);
void OnCompassUpdated(uint64_t time, double magneticNorth, double trueNorth, double accuracy);
void OnCompassUpdated(location::CompassInfo const & info);
void UpdateCompassSensor(int ind, float * arr);
void Invalidate();

View file

@ -1,20 +1,25 @@
#include "Framework.hpp"
#include "../core/jni_helper.hpp"
#include "../../../../../anim/controller.hpp"
extern "C"
{
shared_ptr<location::State> const & GetLocationState()
{
return g_framework->NativeFramework()->GetLocationState();
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_LocationState_switchToNextMode(JNIEnv * env, jobject thiz)
{
g_framework->NativeFramework()->GetLocationState()->SwitchToNextMode();
GetLocationState()->SwitchToNextMode();
}
JNIEXPORT jint JNICALL
Java_com_mapswithme_maps_LocationState_getLocationStateMode(JNIEnv * env, jobject thiz)
{
return g_framework->NativeFramework()->GetLocationState()->GetMode();
return GetLocationState()->GetMode();
}
void LocationStateModeChanged(location::State::Mode mode, shared_ptr<jobject> const & obj)
@ -26,24 +31,24 @@ extern "C"
JNIEXPORT jint JNICALL
Java_com_mapswithme_maps_LocationState_addLocationStateModeListener(JNIEnv * env, jobject thiz, jobject obj)
{
return g_framework->NativeFramework()->GetLocationState()->AddStateModeListener(bind(&LocationStateModeChanged, _1, jni::make_global_ref(obj)));
return GetLocationState()->AddStateModeListener(bind(&LocationStateModeChanged, _1, jni::make_global_ref(obj)));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_LocationState_removeLocationStateModeListener(JNIEnv * env, jobject thiz, jint slotID)
{
g_framework->NativeFramework()->GetLocationState()->RemoveStateModeListener(slotID);
GetLocationState()->RemoveStateModeListener(slotID);
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_LocationState_turnOff(JNIEnv * env, jobject thiz)
{
g_framework->NativeFramework()->GetLocationState()->TurnOff();
GetLocationState()->TurnOff();
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_LocationState_invalidatePosition(JNIEnv * env, jobject thiz)
{
g_framework->NativeFramework()->GetLocationState()->InvalidatePosition();
GetLocationState()->InvalidatePosition();
}
}

View file

@ -5,10 +5,12 @@
#include "../platform/Platform.hpp"
#include "../../../nv_event/nv_event.hpp"
#include "../../../../../base/logging.hpp"
#include "../../../../../map/country_status_display.hpp"
////////////////////////////////////////////////////////////////////////////////////////////
#include "../../../../../base/logging.hpp"
extern "C"
{
JNIEXPORT void JNICALL
@ -26,28 +28,30 @@ extern "C"
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MWMActivity_nativeLocationUpdated(JNIEnv * env, jobject thiz,
jlong time, jdouble lat, jdouble lon, jfloat accuracy,
jdouble altitude, jfloat speed, jfloat bearing)
jlong time, jdouble lat, jdouble lon,
jfloat accuracy, jdouble altitude, jfloat speed, jfloat bearing)
{
const double GPS_VALUE_NOT_SET = -9999999.9;
location::GpsInfo info;
info.m_horizontalAccuracy = accuracy;
info.m_latitude = lat;
info.m_longitude = lon;
info.m_timestamp = time;
info.m_source = location::EAndroidNative;
if (altitude == 0.0)
info.m_altitude = info.m_verticalAccuracy = GPS_VALUE_NOT_SET;
else
info.m_timestamp = static_cast<double>(time) / 1000.0;
info.m_latitude = lat;
info.m_longitude = lon;
if (accuracy > 0.0)
info.m_horizontalAccuracy = accuracy;
if (altitude != 0.0)
{
info.m_altitude = altitude;
// use horizontal accuracy
info.m_verticalAccuracy = accuracy;
}
info.m_course = (bearing == 0.0 ? GPS_VALUE_NOT_SET : bearing);
info.m_speed = (speed == 0.0 ? GPS_VALUE_NOT_SET : speed);
if (bearing > 0.0)
info.m_bearing = bearing;
if (speed > 0.0)
info.m_speed = speed;
g_framework->OnLocationUpdated(info);
}
@ -56,7 +60,10 @@ extern "C"
Java_com_mapswithme_maps_MWMActivity_nativeCompassUpdated(JNIEnv * env, jobject thiz,
jlong time, jdouble magneticNorth, jdouble trueNorth, jdouble accuracy)
{
g_framework->OnCompassUpdated(time, magneticNorth, trueNorth, accuracy);
location::CompassInfo info;
info.m_bearing = (trueNorth >= 0.0) ? trueNorth : magneticNorth;
g_framework->OnCompassUpdated(info);
}
JNIEXPORT jfloatArray JNICALL

View file

@ -594,7 +594,7 @@ public class DownloadResourcesActivity extends MapsWithMeBaseFragmentActivity
}
@Override
public void onDrivingHeadingUpdated(long time, double heading, double accuracy)
public void onDrivingHeadingUpdated(long time, double heading)
{
}

View file

@ -125,13 +125,17 @@ public class Framework
public native static void nativeLoadbookmarks();
// routing
/// @name Routing.
//@{
public native static boolean nativeIsRoutingActive();
public native static void nativeCancelRoutingSession();
public native static void nativeStartRoutingSession(double lat, double lon);
public native static LocationState.RoutingInfo nativeGetRouteFollowingInfo();
//@}
public native static String nativeGetCountryNameIfAbsent(double lat, double lon);
public native static Index nativeGetCountryIndex(double lat, double lon);

View file

@ -19,4 +19,16 @@ public enum LocationState
public native void turnOff();
public native void invalidatePosition();
public static class RoutingInfo
{
public String mDistToTarget;
public String mUnits;
public RoutingInfo(String distToTarget, String units)
{
mDistToTarget = distToTarget;
mUnits = units;
}
}
}

View file

@ -963,32 +963,45 @@ public class MWMActivity extends NvEventQueueActivity
@Override
public void onLocationUpdated(final Location l)
{
nativeLocationUpdated(l.getTime(), l.getLatitude(), l.getLongitude(), l.getAccuracy(), l.getAltitude(), l.getSpeed(), l.getBearing());
nativeLocationUpdated(
l.getTime(),
l.getLatitude(),
l.getLongitude(),
l.getAccuracy(),
l.getAltitude(),
l.getSpeed(),
l.getBearing());
if (mInfoView.getState() != State.HIDDEN)
mInfoView.updateLocation(l);
// TODO get correct values from routing engine
if (Framework.nativeIsRoutingActive())
mTvRoutingDistance.setText(new Random().nextInt() % 100 + " KM");
final LocationState.RoutingInfo info = Framework.nativeGetRouteFollowingInfo();
if (info != null)
mTvRoutingDistance.setText(info.mDistToTarget + info.mUnits);
}
@SuppressWarnings("deprecation")
@Override
public void onCompassUpdated(long time, double magneticNorth, double trueNorth, double accuracy)
{
final double angles[] = {magneticNorth, trueNorth};
final double angles[] = { magneticNorth, trueNorth };
LocationUtils.correctCompassAngles(getWindowManager().getDefaultDisplay().getOrientation(), angles);
nativeCompassUpdated(time, angles[0], angles[1], accuracy);
final double north = (angles[1] >= 0.0 ? angles[1] : angles[0]);
final double north = (angles[1] >= 0.0) ? angles[1] : angles[0];
if (mInfoView.getState() != State.HIDDEN)
mInfoView.updateAzimuth(north);
}
@SuppressWarnings("deprecation")
@Override
public void onDrivingHeadingUpdated(long time, double heading, double accuracy)
public void onDrivingHeadingUpdated(long time, double heading)
{
LocationUtils.correctCompassAngles(getWindowManager().getDefaultDisplay().getOrientation(), new double[]{heading});
nativeCompassUpdated(time, heading, heading, accuracy);
double arr[] = new double[] { heading };
LocationUtils.correctCompassAngles(getWindowManager().getDefaultDisplay().getOrientation(), arr);
heading = arr[0];
nativeCompassUpdated(time, heading, heading, 0.0);
if (mInfoView.getState() != State.HIDDEN)
mInfoView.updateAzimuth(heading);

View file

@ -760,19 +760,16 @@ public class SearchActivity extends MapsWithMeBaseListActivity implements Locati
@Override
public void onCompassUpdated(long time, double magneticNorth, double trueNorth, double accuracy)
{
//
}
@Override
public void onDrivingHeadingUpdated(long time, double heading, double accuracy)
public void onDrivingHeadingUpdated(long time, double heading)
{
//
}
@Override
public void onLocationError(int errorCode)
{
//
}
private boolean isCurrentResult(int id)

View file

@ -157,15 +157,13 @@ public class BookmarkListAdapter extends BaseAdapter
}
@Override
public void onDrivingHeadingUpdated(long time, double heading, double accuracy)
public void onDrivingHeadingUpdated(long time, double heading)
{
//
}
@Override
public void onLocationError(int errorCode)
{
//
}
private class PinHolder

View file

@ -56,7 +56,7 @@ public enum LocationService implements
public void onCompassUpdated(long time, double magneticNorth, double trueNorth, double accuracy);
public void onDrivingHeadingUpdated(long time, double heading, double accuracy);
public void onDrivingHeadingUpdated(long time, double heading);
public void onLocationError(int errorCode);
}
@ -76,9 +76,6 @@ public enum LocationService implements
private GeomagneticField mMagneticField = null;
private LocationProvider mLocationProvider;
private double mLastNorth;
private static final double NOISE_THRESHOLD = 3;
private float[] mGravity = null;
private float[] mGeomagnetic = null;
private final float[] mR = new float[9];
@ -155,11 +152,11 @@ public enum LocationService implements
it.next().onCompassUpdated(time, magneticNorth, trueNorth, accuracy);
}
private void notifyDrivingHeadingUpdated(long time, double heading, double accuracy)
private void notifyDrivingHeadingUpdated(long time, double heading)
{
final Iterator<LocationListener> it = mListeners.iterator();
while (it.hasNext())
it.next().onDrivingHeadingUpdated(time, heading, accuracy);
it.next().onDrivingHeadingUpdated(time, heading);
}
public void startUpdate(LocationListener listener)
@ -225,8 +222,6 @@ public enum LocationService implements
@Override
public void onLocationChanged(Location l)
{
mLogger.d("Location changed: ", l);
// Completely ignore locations without lat and lon
if (l.getAccuracy() <= 0.0)
return;
@ -253,20 +248,9 @@ public enum LocationService implements
private void emitCompassResults(long time, double north, double trueNorth, double offset)
{
if (mDrivingHeading >= 0.0)
notifyDrivingHeadingUpdated(time, mDrivingHeading, offset);
notifyDrivingHeadingUpdated(time, mDrivingHeading);
else
{
if (Math.abs(Math.toDegrees(north - mLastNorth)) < NOISE_THRESHOLD)
{
// ignore noise results. makes compass updates smoother.
}
else
{
notifyCompassUpdated(time, north, trueNorth, offset);
mLastNorth = north;
}
}
notifyCompassUpdated(time, north, trueNorth, offset);
}
@Override
@ -304,7 +288,7 @@ public enum LocationService implements
}
else
{
// positive 'offset' means the magnetic field is rotated east that much from true north
// positive 'offset' means the magnetic field is rotated east that match from true north
final double offset = Math.toRadians(mMagneticField.getDeclination());
final double trueHeading = LocationUtils.correctAngle(magneticHeading, offset);

View file

@ -96,17 +96,27 @@
// TODO: Remove this hack for location changing bug
if (self.navigationController.visibleViewController == self)
{
Framework & f = GetFramework();
f.OnLocationUpdate(info);
Framework & frm = GetFramework();
frm.OnLocationUpdate(info);
[self showPopover];
[[Statistics instance] logLatitude:info.m_latitude
longitude:info.m_longitude
horizontalAccuracy:info.m_horizontalAccuracy
verticalAccuracy:info.m_verticalAccuracy];
longitude:info.m_longitude
horizontalAccuracy:info.m_horizontalAccuracy
verticalAccuracy:info.m_verticalAccuracy];
[self.routeView updateDistance:@"777" withMetrics:@"M"];
if (frm.IsRoutingActive())
{
location::FollowingInfo res;
frm.GetRouteFollowingInfo(res);
if (res.IsValid())
{
[self.routeView updateDistance:[NSString stringWithUTF8String:res.m_distToTarget.c_str()]
withMetrics:[NSString stringWithUTF8String:res.m_unitsSuffix.c_str()]];
}
}
}
}

View file

@ -157,11 +157,10 @@ typedef NS_ENUM(NSUInteger, CellRow)
double lat, lon;
if (![[MapsAppDelegate theApp].m_locationManager getLat:lat Lon:lon])
return;
double const northRad = (info.m_trueHeading < 0) ? info.m_magneticHeading : info.m_trueHeading;
m2::PointD const point = MercatorBounds::FromLatLon(lat, lon);
PlacePageInfoCell * cell = (PlacePageInfoCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:ROW_COMMON inSection:0]];
cell.compassView.angle = ang::AngleTo(point, [self pinPoint]) + northRad;
cell.compassView.angle = ang::AngleTo(MercatorBounds::FromLatLon(lat, lon), [self pinPoint]) + info.m_bearing;
}
- (CellRow)cellRowForIndexPath:(NSIndexPath *)indexPath

View file

@ -120,16 +120,34 @@
- (void)location:(CLLocation *)location toGpsInfo:(location::GpsInfo &)info
{
info.m_horizontalAccuracy = location.horizontalAccuracy;
info.m_source = location::EAppleNative;
info.m_latitude = location.coordinate.latitude;
info.m_longitude = location.coordinate.longitude;
info.m_timestamp = [location.timestamp timeIntervalSince1970];
info.m_source = location::EAppleNative;
info.m_verticalAccuracy = location.verticalAccuracy;
info.m_altitude = location.altitude;
info.m_course = location.course;
info.m_speed = location.speed;
if (location.horizontalAccuracy >= 0.0)
info.m_horizontalAccuracy = location.horizontalAccuracy;
if (location.verticalAccuracy >= 0.0)
{
info.m_verticalAccuracy = location.verticalAccuracy;
info.m_altitude = location.altitude;
}
if (location.course >= 0.0)
info.m_bearing = location.course;
if (location.speed >= 0.0)
info.m_speed = location.speed;
}
- (void)heading:(CLHeading *)heading toCompassInfo:(location::CompassInfo &)info
{
if (heading.trueHeading >= 0.0)
info.m_bearing = my::DegToRad(heading.trueHeading);
else if (heading.headingAccuracy >= 0.0)
info.m_bearing = my::DegToRad(heading.magneticHeading);
}
- (void)triggerCompass
@ -137,7 +155,7 @@
[self locationManager:m_locationManager didUpdateHeading:m_locationManager.heading];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)heading
{
// Stop passing driving course if last time stamp for GPS location is later than 20 seconds.
if (m_lastLocationTime == nil || ([m_lastLocationTime timeIntervalSinceNow] < -20.0))
@ -145,13 +163,9 @@
if (!m_isCourse)
{
location::CompassInfo newInfo;
newInfo.m_magneticHeading = my::DegToRad(newHeading.magneticHeading);
newInfo.m_trueHeading = my::DegToRad(newHeading.trueHeading);
newInfo.m_accuracy = my::DegToRad(newHeading.headingAccuracy);
newInfo.m_timestamp = [newHeading.timestamp timeIntervalSince1970];
[self notifyCompassUpdate:newInfo];
location::CompassInfo info;
[self heading:heading toCompassInfo:info];
[self notifyCompassUpdate:info];
}
}
@ -186,13 +200,9 @@
{
m_isCourse = YES;
location::CompassInfo newInfo;
newInfo.m_magneticHeading = my::DegToRad(newLocation.course);
newInfo.m_trueHeading = newInfo.m_magneticHeading;
newInfo.m_accuracy = 10.0;
newInfo.m_timestamp = [newLocation.timestamp timeIntervalSince1970];
[self notifyCompassUpdate:newInfo];
location::CompassInfo info;
info.m_bearing = my::DegToRad(newLocation.course);
[self notifyCompassUpdate:info];
}
else
m_isCourse = NO;

View file

@ -60,7 +60,10 @@
#define DEFAULT_BOOKMARK_TYPE "placemark-red"
using namespace storage;
using namespace routing;
using namespace location;
#ifdef FIXED_LOCATION
@ -106,13 +109,13 @@ void Framework::RemoveMap(string const & file)
m_model.RemoveMap(file);
}
void Framework::OnLocationError(location::TLocationError error)
void Framework::OnLocationError(TLocationError error)
{}
void Framework::OnLocationUpdate(location::GpsInfo const & info)
void Framework::OnLocationUpdate(GpsInfo const & info)
{
#ifdef FIXED_LOCATION
location::GpsInfo rInfo(info);
GpsInfo rInfo(info);
// get fixed coordinates
m_fixedPos.GetLon(rInfo.m_longitude);
@ -124,35 +127,35 @@ void Framework::OnLocationUpdate(location::GpsInfo const & info)
if (m_fixedPos.HasNorth())
{
// pass compass value (for devices without compass)
location::CompassInfo compass;
CompassInfo compass;
compass.m_magneticHeading = compass.m_trueHeading = 0.0;
compass.m_timestamp = rInfo.m_timestamp;
OnCompassUpdate(compass);
}
#else
location::GpsInfo const & rInfo = info;
GpsInfo const & rInfo = info;
#endif
shared_ptr<location::State> const & state = m_informationDisplay.locationState();
shared_ptr<State> const & state = GetLocationState();
state->OnLocationUpdate(rInfo);
CheckLocationForRouting();
m_balloonManager.LocationChanged(rInfo);
CheckLocationForRouting(info);
if (state->IsModeChangeViewport())
UpdateUserViewportChanged();
}
void Framework::OnCompassUpdate(location::CompassInfo const & info)
void Framework::OnCompassUpdate(CompassInfo const & info)
{
#ifdef FIXED_LOCATION
location::CompassInfo rInfo(info);
CompassInfo rInfo(info);
m_fixedPos.GetNorth(rInfo.m_trueHeading);
#else
location::CompassInfo const & rInfo = info;
CompassInfo const & rInfo = info;
#endif
m_informationDisplay.locationState()->OnCompassUpdate(rInfo);
GetLocationState()->OnCompassUpdate(rInfo);
}
void Framework::StopLocationFollow()
@ -212,6 +215,7 @@ Framework::Framework()
m_stringsBundle.SetDefaultString("my_places", "My Places");
m_stringsBundle.SetDefaultString("my_position", "My Position");
m_stringsBundle.SetDefaultString("routes", "Routes");
m_stringsBundle.SetDefaultString("recalculating_route", "Recalculating ...");
m_guiController->SetStringsBundle(&m_stringsBundle);
@ -255,7 +259,7 @@ Framework::Framework()
LOG(LDEBUG, ("Guides info initialized"));
#endif
m_routingSession.SetRouter(new routing::OsrmRouter(&m_model.GetIndex(), [this] (m2::PointD const & pt)
m_routingSession.SetRouter(new OsrmRouter(&m_model.GetIndex(), [this] (m2::PointD const & pt)
{
return GetSearchEngine()->GetCountryFile(pt);
}));
@ -290,7 +294,7 @@ TStatus Framework::GetCountryStatus(TIndex const & index) const
return m_storage.CountryStatusEx(index);
}
string Framework::GetCountryName(storage::TIndex const & index) const
string Framework::GetCountryName(TIndex const & index) const
{
string group, name;
m_storage.GetGroupAndCountry(index, group, name);
@ -309,7 +313,7 @@ m2::RectD Framework::GetCountryBounds(TIndex const & index) const
return GetCountryBounds(m_storage.CountryByIndex(index).GetFile().m_fileName);
}
void Framework::ShowCountry(storage::TIndex const & index)
void Framework::ShowCountry(TIndex const & index)
{
StopLocationFollow();
@ -700,22 +704,21 @@ void Framework::DrawAdditionalInfo(shared_ptr<PaintEvent> const & e)
}
/// Function for calling from platform dependent-paint function.
void Framework::DoPaint(shared_ptr<PaintEvent> const & e)
{
if (m_renderPolicy)
{
m_renderPolicy->DrawFrame(e, m_navigator.Screen());
// don't render additional elements if guiController wasn't initialized
// Don't render additional elements if guiController wasn't initialized.
if (m_guiController->GetCacheScreen() != NULL)
DrawAdditionalInfo(e);
}
}
m2::PointD Framework::GetViewportCenter() const
m2::PointD const & Framework::GetViewportCenter() const
{
return m_navigator.Screen().GlobalRect().GlobalCenter();
return m_navigator.Screen().GetOrg();
}
void Framework::SetViewportCenter(m2::PointD const & pt)
@ -727,11 +730,8 @@ void Framework::SetViewportCenter(m2::PointD const & pt)
shared_ptr<MoveScreenTask> Framework::SetViewportCenterAnimated(m2::PointD const & endPt)
{
anim::Controller::Guard guard(GetAnimController());
ScreenBase const & s = m_navigator.Screen();
m2::PointD const & startPt = s.GetOrg();
double const speed = m_navigator.ComputeMoveSpeed(startPt, endPt);
return m_animator.MoveScreen(startPt, endPt, speed);
m2::PointD const & startPt = GetViewportCenter();
return m_animator.MoveScreen(startPt, endPt, m_navigator.ComputeMoveSpeed(startPt, endPt));
}
m2::AnyRectD Framework::ToRotated(m2::RectD const & rect) const
@ -1089,7 +1089,7 @@ search::Engine * Framework::GetSearchEngine() const
return m_pSearchEngine.get();
}
storage::TIndex Framework::GetCountryIndex(m2::PointD const & pt) const
TIndex Framework::GetCountryIndex(m2::PointD const & pt) const
{
return m_storage.FindIndexByFile(GetSearchEngine()->GetCountryFile(pt));
}
@ -1127,7 +1127,7 @@ bool Framework::Search(search::SearchParams const & params)
bool Framework::GetCurrentPosition(double & lat, double & lon) const
{
shared_ptr<location::State> locationState = m_informationDisplay.locationState();
shared_ptr<State> locationState = m_informationDisplay.locationState();
if (locationState->IsModeHasPosition())
{
@ -1619,7 +1619,7 @@ Navigator & Framework::GetNavigator()
return m_navigator;
}
shared_ptr<location::State> const & Framework::GetLocationState() const
shared_ptr<State> const & Framework::GetLocationState() const
{
return m_informationDisplay.locationState();
}
@ -1670,7 +1670,7 @@ UserMark const * Framework::GetUserMark(m2::PointD const & pxPoint, bool isLongP
m2::AnyRectD rect;
m_navigator.GetTouchRect(pxPoint, TOUCH_PIXEL_RADIUS * GetVisualScale(), rect);
shared_ptr<location::State> const & locationState = GetLocationState();
shared_ptr<State> const & locationState = GetLocationState();
if (locationState->IsModeHasPosition())
{
m2::PointD const & glPivot = locationState->Position();
@ -1814,7 +1814,7 @@ void Framework::UpdateSavedDataVersion()
Settings::Set("DataVersion", m_storage.GetCurrentDataVersion());
}
bool Framework::GetGuideInfo(storage::TIndex const & index, guides::GuideInfo & info) const
bool Framework::GetGuideInfo(TIndex const & index, guides::GuideInfo & info) const
{
return m_storage.GetGuideManager().GetGuideInfo(m_storage.CountryFileName(index), info);
}
@ -1828,19 +1828,18 @@ bool Framework::IsRoutingActive() const
bool Framework::StartRoutingSession(m2::PointD const & destination)
{
shared_ptr<location::State> state = GetLocationState();
shared_ptr<State> const & state = GetLocationState();
if (!GetPlatform().HasRouting() || !state->IsModeHasPosition())
return false;
if (IsRoutingActive())
CancelRoutingSession();
m_routingSession.BuildRoute(state->Position(), destination,
[this, state](routing::Route const & route, routing::IRouter::ResultCode e)
{
InsertRoute(route);
state->StartRoutingMode();
});
m_routingSession.BuildRoute(state->Position(), destination, [&](Route const & route, routing::IRouter::ResultCode e)
{
InsertRoute(route);
state->StartRoutingMode();
});
return true;
}
@ -1868,7 +1867,7 @@ void Framework::CancelRoutingSession()
Invalidate();
}
void Framework::InsertRoute(routing::Route const & route)
void Framework::InsertRoute(Route const & route)
{
string const categoryName = m_stringsBundle.GetString("routes");
BookmarkCategory * cat = 0;
@ -1905,20 +1904,33 @@ void Framework::InsertRoute(routing::Route const & route)
Invalidate();
}
void Framework::CheckLocationForRouting()
void Framework::CheckLocationForRouting(GpsInfo const & info)
{
if (!IsRoutingActive())
return;
shared_ptr<location::State> const & state = GetLocationState();
shared_ptr<State> const & state = GetLocationState();
m2::PointD const & position = state->Position();
if (m_routingSession.OnLocationPositionChanged(position, state->GetErrorRadius()) == routing::RoutingSession::RouteLeft)
switch (m_routingSession.OnLocationPositionChanged(position, state->GetErrorRadius()))
{
m_routingSession.RebuildRoute(position, [this] (routing::Route const & route, routing::IRouter::ResultCode e)
{
InsertRoute(route);
});
case RoutingSession::RouteLeft:
m_routingSession.RebuildRoute(position, [this] (Route const & route, routing::IRouter::ResultCode e)
{
InsertRoute(route);
});
break;
case RoutingSession::OnRoute:
//m_routingSession.UpdatePosition(position, info);
break;
default:
break;
}
}
////////////////////////////////////////////////////////////////////////////////////
void Framework::GetRouteFollowingInfo(location::FollowingInfo & info)
{
}

View file

@ -303,7 +303,7 @@ public:
int GetDrawScale() const;
m2::PointD GetViewportCenter() const;
m2::PointD const & GetViewportCenter() const;
void SetViewportCenter(m2::PointD const & pt);
shared_ptr<MoveScreenTask> SetViewportCenterAnimated(m2::PointD const & endPt);
@ -482,10 +482,11 @@ public:
bool IsRoutingActive() const;
bool StartRoutingSession(m2::PointD const & destination);
void CancelRoutingSession();
void GetRouteFollowingInfo(location::FollowingInfo & info);
private:
void RemoveRoute();
void InsertRoute(routing::Route const & route);
void CheckLocationForRouting();
void CheckLocationForRouting(location::GpsInfo const & info);
//@}
};

View file

@ -320,10 +320,7 @@ void State::OnCompassUpdate(location::CompassInfo const & info)
{
SetModeInfo(IncludeModeBit(m_modeInfo, KnownDirectionBit));
if (info.m_trueHeading >= 0.0)
m_drawDirection = info.m_trueHeading;
else
m_drawDirection = info.m_magneticHeading;
m_drawDirection = info.m_bearing;
AnimateFollow();
invalidate();

View file

@ -1,8 +1,9 @@
#pragma once
#include "../base/base.hpp"
#include "../std/string.hpp"
#include "../std/vector.hpp"
#include "../std/function.hpp"
namespace location
{
@ -29,6 +30,12 @@ namespace location
class GpsInfo
{
public:
GpsInfo()
: m_horizontalAccuracy(100.0), // use as a default accuracy
m_altitude(0.0), m_verticalAccuracy(-1.0), m_bearing(-1.0), m_speed(-1.0)
{
}
TLocationSource m_source;
double m_timestamp; //!< seconds from 1st Jan 1970
double m_latitude; //!< degrees
@ -36,21 +43,22 @@ namespace location
double m_horizontalAccuracy; //!< metres
double m_altitude; //!< metres
double m_verticalAccuracy; //!< metres
double m_course; //!< positive degrees from the true North
double m_bearing; //!< positive degrees from the true North
double m_speed; //!< metres per second
bool HasAltitude() const { return m_verticalAccuracy >= 0.; }
bool HasBearing() const { return m_course >= 0.; }
bool HasSpeed() const { return m_speed >= 0.; }
//bool HasAltitude() const { return m_verticalAccuracy >= 0.0; }
//bool HasBearing() const { return m_bearing >= 0.0; }
bool HasSpeed() const { return m_speed >= 0.0; }
};
class CompassInfo
{
public:
double m_timestamp; //!< how many seconds ago the heading was retrieved
double m_magneticHeading; //!< positive radians from the magnetic North
double m_trueHeading; //!< positive radians from the true North
double m_accuracy; //!< offset from the magnetic to the true North in radians
//double m_timestamp; //!< seconds from 1st Jan 1970
//double m_magneticHeading; //!< positive radians from the magnetic North
//double m_trueHeading; //!< positive radians from the true North
//double m_accuracy; //!< offset from the magnetic to the true North in radians
double m_bearing; //!< positive radians from the true North
};
static inline bool IsLatValid(double lat)
@ -62,4 +70,16 @@ namespace location
return lon != 0. && lon < 180. && lon > -180.;
}
class FollowingInfo
{
public:
/// @name Formatted covered distance with measurement units suffix.
//@{
string m_distToTarget;
string m_unitsSuffix;
//@}
bool IsValid() const { return !m_distToTarget.empty(); }
};
} // namespace location