[android] Enabled alt/speed/bearing in location updates

This commit is contained in:
Alex Zolotarev 2013-06-07 00:56:29 +03:00 committed by Alex Zolotarev
parent 9d50951c89
commit c94dd547f4
5 changed files with 31 additions and 14 deletions

View file

@ -5,7 +5,6 @@
#include "../core/render_context.hpp"
#include "../../../../../map/framework.hpp"
#include "../../../../../map/measurement_utils.hpp"
#include "../../../../../gui/controller.hpp"
@ -63,14 +62,8 @@ namespace android
m_work.OnLocationError(static_cast<location::TLocationError>(errorCode));
}
void Framework::OnLocationUpdated(uint64_t time, double lat, double lon, float accuracy)
void Framework::OnLocationUpdated(location::GpsInfo const & info)
{
location::GpsInfo info;
info.m_timestamp = static_cast<double>(time);
info.m_latitude = lat;
info.m_longitude = lon;
info.m_horizontalAccuracy = accuracy;
m_work.OnLocationUpdate(info);
}
@ -81,7 +74,6 @@ namespace android
info.m_magneticHeading = magneticNorth;
info.m_trueHeading = trueNorth;
info.m_accuracy = accuracy;
m_work.OnCompassUpdate(info);
}

View file

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

View file

@ -26,9 +26,30 @@ extern "C"
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MWMActivity_nativeLocationUpdated(JNIEnv * env, jobject thiz,
jlong time, jdouble lat, jdouble lon, jfloat accuracy)
jlong time, jdouble lat, jdouble lon, jfloat accuracy,
jdouble altitude, jfloat speed, jfloat bearing)
{
g_framework->OnLocationUpdated(time, lat, lon, accuracy);
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_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);
g_framework->OnLocationUpdated(info);
}
JNIEXPORT void JNICALL

View file

@ -735,7 +735,7 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
mMyPositionButton.setSelected(true);
}
nativeLocationUpdated(l.getTime(), l.getLatitude(), l.getLongitude(), l.getAccuracy());
nativeLocationUpdated(l.getTime(), l.getLatitude(), l.getLongitude(), l.getAccuracy(), l.getAltitude(), l.getSpeed(), l.getBearing());
}
@Override
@ -1119,7 +1119,7 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
private native void nativeDestroy();
private native void nativeOnLocationError(int errorCode);
private native void nativeLocationUpdated(long time, double lat, double lon, float accuracy);
private native void nativeLocationUpdated(long time, double lat, double lon, float accuracy, double altitude, float speed, float bearing);
private native void nativeCompassUpdated(long time, double magneticNorth, double trueNorth, double accuracy);
private native boolean nativeIsInChina(double lat, double lon);

View file

@ -295,6 +295,10 @@ public class LocationService implements LocationListener, SensorEventListener, W
public void onLocationChanged(Location l)
{
mLogger.d("Location changed", l);
// Completely ignore locations without lat and lon
if (l.getAccuracy() <= 0.)
return;
// hack to avoid time zone troubles
l.setTime(System.currentTimeMillis());
if (LocationUtils.isFirstOneBetterLocation(l, m_lastLocation))