GPS - Java

KikeCentolo

Member
Licensed User
Longtime User
It is possible transalte this code to BA4? and the more important...Will activate the gps?


PHP:
privateLocationManagerlocMgr;
privateLocationListeneronLocationChange;


locMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
onLocationChange = newLocationListener() {
@Override
publicvoidonLocationChanged(android.location.Location location) {
longitutdeTextView.setText("Longitud: " + location.getLongitude());
latitudeTextView.setText("Latitud: " + location.getLatitude());
Log.i(LOG_TAG, "Received Location update.");
}
@Override
publicvoidonProviderDisabled(String provider) {
Log.i(LOG_TAG, "Location provider " + provider + " has been disabled.");
}
@Override
publicvoidonProviderEnabled(String provider) {
Log.i(LOG_TAG, "Location provider " + provider + " has been enabled.");            
}

@Override
publicvoidonStatusChanged(String provider, int status,
               Bundle extras) {
Log.i(LOG_TAG, "Location provider " + provider + " has changed status to " + status);
}
};

toggleButton.setOnClickListener(newView.OnClickListener() {
@Override
publicvoidonClick(View v) {
   if (toggleButton.isChecked()){
   locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 
                     0, 0f, onLocationChange);
}
else {
   locMgr.removeUpdates(onLocationChange);
   }
   }   
});


android.location.Location location = locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location == null)
location = locMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
longitutdeTextView.setText("Longitud: " + location.getLongitude());
latitudeTextView.setText("Latitud: " + location.getLatitude());
}
else {
longitutdeTextView.setText("Longitud: No disponible");
latitudeTextView.setText("Latitud: No disponible");
}


Thanks
 
Top