Added native method to format lat-lon separately.

This commit is contained in:
Dmitry Yunitsky 2014-08-06 12:37:50 +03:00 committed by Alex Zolotarev
parent e4a1650cad
commit 63c2234ba4
5 changed files with 35 additions and 1 deletions

View file

@ -859,6 +859,24 @@ extern "C"
return jni::ToJavaString(env, MeasurementUtils::FormatLatLon(lat, lon, 6));
}
JNIEXPORT jobjectArray JNICALL
Java_com_mapswithme_maps_Framework_nativeFormatLatLonToArr(JNIEnv * env, jclass clazz, jdouble lat, jdouble lon, jboolean useDMSFormat)
{
string slat, slon;
if (useDMSFormat)
MeasurementUtils::FormatLatLonAsDMS(lat, lon, slat, slon, 2);
else
MeasurementUtils::FormatLatLon(lat, lon, slat, slon, 6);
jclass klass = env->FindClass("java/lang/String");
jobjectArray arr = env->NewObjectArray(2, klass, 0);
env->SetObjectArrayElement(arr, 0, jni::ToJavaString(env, slat));
env->SetObjectArrayElement(arr, 1, jni::ToJavaString(env, slon));
return arr;
}
JNIEXPORT jobject JNICALL
Java_com_mapswithme_maps_Framework_nativeFormatAltitude(JNIEnv * env, jclass clazz, jdouble alt)
{

View file

@ -79,6 +79,8 @@ public class Framework
public native static String nativeFormatLatLon(double lat, double lon, boolean useDMSFormat);
public native static String[] nativeFormatLatLonToArr(double lat, double lon, boolean useDMSFormat);
public native static String nativeFormatAltitude(double alt);
public native static String nativeFormatSpeed(double speed);

View file

@ -554,7 +554,7 @@ public class MapInfoView extends LinearLayout implements View.OnClickListener
{
final double lat = mMapObject.getLat();
final double lon = mMapObject.getLon();
final String[] latLon = Framework.nativeFormatLatLon(lat, lon, mIsLatLonDms).split(" ");
final String[] latLon = Framework.nativeFormatLatLonToArr(lat, lon, mIsLatLonDms);
if (latLon.length == 2)
{
mTvLat.setText(latLon[0]);

View file

@ -108,6 +108,12 @@ string FormatLatLonAsDMS(double lat, double lon, int dac)
FormatLatLonAsDMSImpl(lon, 'E', 'W', dac));
}
void FormatLatLonAsDMS(double lat, double lon, string & latText, string & lonText, int dac)
{
latText = FormatLatLonAsDMSImpl(lat, 'N', 'S', dac);
lonText = FormatLatLonAsDMSImpl(lon, 'E', 'W', dac);
}
void FormatMercatorAsDMS(m2::PointD const & mercator, string & lat, string & lon, int dac)
{
lat = FormatLatLonAsDMSImpl(MercatorBounds::YToLat(mercator.y), 'N', 'S', dac);
@ -125,6 +131,12 @@ string FormatLatLon(double lat, double lon, int dac)
return strings::to_string_dac(lat, dac) + " " + strings::to_string_dac(lon, dac);
}
void FormatLatLon(double lat, double lon, string & latText, string & lonText, int dac)
{
latText = strings::to_string_dac(lat, dac);
lonText = strings::to_string_dac(lon, dac);
}
string FormatMercator(m2::PointD const & mercator, int dac)
{
return FormatLatLon(MercatorBounds::YToLat(mercator.y), MercatorBounds::XToLon(mercator.x), dac);

View file

@ -30,10 +30,12 @@ string FormatSpeed(double metersPerSecond);
/// @param[in] dac Digits after comma in seconds.
/// Use dac == 3 for our common conversions.
string FormatLatLonAsDMS(double lat, double lon, int dac = 3);
void FormatLatLonAsDMS(double lat, double lon, string & latText, string & lonText, int dac = 3);
string FormatMercatorAsDMS(m2::PointD const & mercator, int dac = 3);
void FormatMercatorAsDMS(m2::PointD const & mercator, string & lat, string & lon, int dac = 3);
/// Simple decimal degrees formating
string FormatLatLon(double lat, double lon, int dac = 6);
void FormatLatLon(double lat, double lon, string & latText, string & lonText, int dac = 6);
string FormatMercator(m2::PointD const & mercator, int dac = 6);
void FormatMercator(m2::PointD const & mercator, string & lat, string & lon, int dac = 6);