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

时间:2014-01-30 12:10:29

标签: android location double

我正在开发一个位置应用。我想创建一个接近警报。为此我有2个edittexts,我设置纬度和经度。

首先,我使用getLastKnownLocation()从我的位置自动检索位置coordenates,然后将这些值保存到edittexts中。但是,我需要能够手动将位置共同设置到edittexts中以设置接近警报。

因此,要创建接近警报,我必须从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的十进制值转换回double值。

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

好吧,我终于解决了这个问题。

设置String或类似的位置坐标的double值:

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()));
相关问题