2014-01-30 4 views
0

위치 앱에서 작업하고 있습니다. 근접 알림을 만들고 싶습니다. 이를 위해 위도와 경도를 설정하는 2 개의 편집 문구가 있습니다.edittext에서 값을 가져 오는 위치 위도/경도 설정

우선, getLastKnownLocation()을 사용하여 내 위치에서 좌표를 자동으로 검색하고이 값을 편집 문구에 저장합니다. 하지만, 근접 경고를 설정하기 위해 수동으로 위치를 편집 문안으로 수동으로 설정할 수 있어야합니다.

근접 경고를 만들려면 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 값으로 변환하는 방법입니다.

답변

0

음, 방금 마침내 해결했습니다.

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

당신은 mLocation.setLatitute(Double.parseDouble(latitudeEditText.getText().toString()));
유사하게 사용할 수 있습니다
mLocation.setLongitude(Double.parseDouble(longitudeEditText.getText().toString()));
을 나는 그것이 도움이되기를 바랍니다.

+0

u는'글고을 확인해야한다는 점에 유의하시기 바랍니다 :

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

이 같은 백을 수행합니다

는 위치의 두 배 값이 String 또는 유사한 좌표 설정하려면 이 작업을 수행하기 전에 값을 지정하십시오. 즉,'EditText'는 double 값으로 변환 될 수있는 값을 포함합니다. – SMR

+0

이것은 어떤 종류의 예외를 사용하여 수행해야합니까? 당신이 모범이 될 수 있겠습니까? 나는 여전히 예외에 대해 조금 더 배워야한다. – masmic

+0

글쎄,이 솔루션이 작동하지 않는 것 같다. 이것은 LogCat에서 얻는 것입니다 :'java.lang.NumberFormatException : 잘못된 double : "43,249502"' – masmic

관련 문제