Olá a todos, estou tentando montar uma app que pegue os valores de
latitude e longitude e quando acionado um evento em um buttun atribua
esses valores em edittexts.
abaixo o codigo que eu estou fazendo, alguem sabe me dizer em que
estou errando?
public class principal extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btGetLocation = (Button)
findViewById(R.id.btGetLocation);
btGetLocation.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
// AndroidManifest.xml must have the
following permission:
// <uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"/>
LocationManager locationManager =
(LocationManager)
getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
0, 0, new LocationListener() {
public void
onStatusChanged(String provider, int status, Bundle
extras) {
// called when the
provider status changes. Possible status:
OUT_OF_SERVICE, TEMPORARILY_UNAVAILABLE or AVAILABLE.
}
public void
onProviderEnabled(String provider) {
// called when the
provider is enabled by the user
}
public void
onProviderDisabled(String provider) {
// called when the
provider is disabled by the user, if it's
already disabled, it's called immediately after
requestLocationUpdates
}
public void
onLocationChanged(Location location) {
//double latitute =
location.getLatitude();
//double longitude =
location.getLongitude();
// do whatever you
want with the coordinates
EditText x =
(EditText) findViewById(R.id.edLocationX);
EditText y =
(EditText) findViewById(R.id.edLocationY);
x.setText(String.valueOf(location.getLatitude()));
y.setText(String.valueOf(location.getLongitude()));
}
});
}
});
}
[androidbrasil-dev] GPS geolocation
10:18 |
Assinar:
Postar comentários (Atom)






0 comentários:
Postar um comentário