How to Get the current location of my device
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
How do I get the current GPS location programmatically in Android?
我有一个应用程序,我想获取当前位置。
我也希望得到纬度和经度所以我存储它并返回那个位置。
怎么办......
尝试以下代码段,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import android.location.Location; import android.location.LocationListener; import android.os.Bundle; public class LocListener implements LocationListener { private static double lat =0.0; private static double lon = 0.0; private static double alt=0.0; private static double speed = 0.0; public static double getLat() { return lat; } public static double getLon() { return lon; } public static double getAlt() { return alt; } public static double getSpeed() { return speed; } @Override public void onLocationChanged(Location location) { lat = location.getLatitude(); lon = location.getLongitude(); alt=location.getAltitude(); speed = location.getSpeed(); } @Override public void onProviderDisabled(String provider) {} @Override public void onProviderEnabled(String provider) {} @Override public void onStatusChanged(String provider, int status, Bundle extras) {} } |
我发现此链接非常有用..
你可以看一下..
这里