Created
December 17, 2010 05:28
-
-
Save stivio00/744525 to your computer and use it in GitHub Desktop.
localization on android,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Stephen Krol | |
*/ | |
package org.mlea; | |
import android.app.Activity; | |
import android.location.Location; | |
import android.location.LocationManager; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.widget.Button; | |
import android.widget.TextView; | |
public class MainActivity extends Activity implements OnClickListener { | |
private LocationManager mLocationManager; | |
private TextView infoLabel; | |
private Button updateButton; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
// Setting up the GUI | |
setContentView(R.layout.main); | |
// Retiring some useful GUI objects | |
infoLabel = (TextView) findViewById(R.id.info_label); | |
updateButton = (Button) findViewById(R.id.update_button); | |
updateButton.setOnClickListener(this); | |
// Getting the instance of the location service | |
mLocationManager = | |
(LocationManager) getSystemService(LOCATION_SERVICE); | |
} | |
@Override | |
public void onClick(View v) { | |
StringBuilder output = new StringBuilder(); | |
output.append("Providers :\n"); | |
for(String prov: mLocationManager.getAllProviders()) { | |
output.append(" -- "+prov+" ; "); | |
output.append( | |
"enable="+mLocationManager.isProviderEnabled(prov)+"\n"); | |
} | |
String provider = LocationManager.NETWORK_PROVIDER; | |
output.append("\n\n"+"Best Provider: "+provider); | |
Location location = | |
mLocationManager.getLastKnownLocation(provider); | |
if(location==null){ | |
output.append("\n\nNo last Know location, sorry!"); | |
}else{ | |
output.append("\n\nlatitude : "+location.getLatitude()+"\n"); | |
output.append("longitud : "+location.getLongitude()+"\n"); | |
output.append("Accurancy : "+location.getAccuracy()+"\n"); | |
} | |
infoLabel.setText(output.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment