Android 取GPS的经纬度

LocationManager loctionManager=(LocationManager) getSystemService(Context.LOCATION_SERVICE);
loctionManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 20000, 0, locationListener);//监听位置变化,20秒一次,距离0米以上 
private final LocationListener locationListener = new LocationListener()
{
    public void onLocationChanged(Location location)
    {
        if (location != null)
        {
            Log.d("onLocationChanged", location.getLatitude()+","+location.getLongitude());
        }
    }

    public void onProviderDisabled(String provider)
    {
        Log.d("onProviderDisabled", provider);
    }

    public void onProviderEnabled(String provider)
    {
        Log.d("onProviderEnabled", provider);
    }

    public void onStatusChanged(String provider, int status, Bundle extras)
    {
        Log.d("onStatusChanged", provider+",status="+status+",extras="+extras);
    }
};
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/><!-- 使用GPS权限 --> 
注意:不用后一定要做清理工作:
loctionManager.removeUpdates(locationListener);

 

上一篇:第2组 Beta (2/6)(刘阳)


下一篇:在网络暴力面前,如何避免泄漏过多的个人信息