设置位置纬度/经度从Edittext获取值



我正在使用位置应用程序。我想创建一个接近警报。为此,我有2个iDittext,我设置了纬度和经度。

首先,我使用getLastKnownLocation()从位置自动检索位置协调,然后将此值保存到EditTexts中。但是,我需要能够手动将位置坐标设置为EditTexts以设置接近警报。

so,要创建接近警报,我必须从EditText获得坐标,这可以进行一些值转换。

,但我不知道的是如何做这种转换。为了更好地构成,这是代码:

//Get location depending on the better service
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
String provider = mLocationManager.getBestProvider(mCriteria, true);
Location location = mLocationManager.getLastKnownLocation(provider);
//Make conversion to show Location coordinates in edittexts
private static final NumberFormat nf = new DecimalFormat("##.########");
latitudeEditText.setText(nf.format(mLocation.getLatitude()));
longitudeEditText.setText(nf.format(mLocation.getLongitude()));

这是我需要帮助的地方。现在,我需要从latitudeEditTextlongitudeEditText获取值,然后再次将它们设置为mLocation

我认为这将以以下方式完成:mLocation.setLatitude("double value"),但我疑问是如何使转换从EditText的小数值重新回到双重值。

您可以使用mLocation.setLatitute(Double.parseDouble(latitudeEditText.getText().toString()));
同样:
mLocation.setLongitude(Double.parseDouble(longitudeEditText.getText().toString()));
我希望它有帮助。

好吧,我终于解决了。

设置字符串或类似位置坐标的双重值:

latitudeEditText.setText(mLocation.convert(mLocation.getLatitude(), mLocation.FORMAT_DEGREES));
longitudeEditText.setText(mLocation.convert(mLocation.getLongitude(), mLocation.FORMAT_DEGREES));

做同样的后背:

mLocation.setLatitude(mLocation.convert(latitudeEditText.getText().toString()));
mLocation.setLongitude(mLocation.convert(longitudeEditText.getText().toString()));

最新更新