how to convert value from getLongitude() and getLatitude() to format that can be accepted by the EditText?
it works if i put them into Toast like this
String message = "Current Location \nLongitude: "+location.getLongitude()+"\nLatitude: "+location.getLatitude();
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
but if i put them into EditText like this, the application will stopped and error
tv_obj_long.setText(location.getLongitude());
tv_obj_lat.setText(location.getLatitude());
i think the format is wrong, i’m trying with Double.toString() but it still error
how to fix this?
thanks
this is my code on the button
btn_obj_useKor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
showCurrentLocation();
}
});
this is the function called by the button
public void showCurrentLocation() {
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
showToastStatus(location);
tv_obj_long.setText(String.valueOf(location.getLongitude()));
tv_obj_lat.setText(String.valueOf(location.getLatitude()));
}else{
Toast.makeText(getApplicationContext(), "Terjadi Kesalahan dalam pengambilan koordinat", Toast.LENGTH_LONG).show();
}
};
this is the toast that works
public void showToastStatus(Location location){
String message = "Current Location \nLongitude: "+location.getLongitude()+"\nLatitude: "+location.getLatitude();
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}
and this is my xml
<TextView
android:text="Longitude"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/tv_obj_long"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:text="Latitude"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/tv_obj_lat"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
help me guys –_–
I know the problem now,
I placed the declaration in wrong place
Look at this
i added this code on second line
and it works!!
i placed that code in onCreate before
T___T