This article describes the simple method of Android to obtain latitude and longitude. Share it for your reference, as follows:
public void getLoc() { // Location LocationManager locationManager; LocationListener locationListener; Location location; String contextService = Context.LOCATION_SERVICE; String provider; double lat; double lon; locationManager = (LocationManager) getSystemService(contextService); Criteria criteria = new Criteria(); (Criteria.ACCURACY_FINE);// High precision (false);// No alignment required (false);// No position required (true);// Allows for expenses (Criteria.POWER_LOW);// Low power consumption // From available location providers, match the best providers of the above standards provider = (criteria, true); // Get the last change position location = (provider); locationListener = new LocationListener() { public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onLocationChanged(Location location) { lat = (); lon = (); ("android_lat", (lat)); ("android_lon", (lon)); } }; // The monitoring position changes, once every 2 seconds, and the distance is more than 10 meters (provider, 2000, 10, locationListener); }
For more information about Android related content, please check out the topic of this site:Android development introduction and advanced tutorial》、《Android View View Tips Summary》、《Android programming activity operation skills summary》、《Summary of Android's SQLite database skills》、《Summary of Android operating json format data skills》、《Android database operation skills summary》、《Android file operation skills summary》、《A summary of SD card operation methods for Android programming and development》、《Android resource operation skills summary"and"Android control usage summary》
I hope this article will be helpful to everyone's Android programming design.