【问题标题】:how to get Updated location & Disable GPS after getting it in android?在 android 中获取更新位置和禁用 GPS 后如何获取?
【发布时间】:2010-10-27 06:23:08
【问题描述】:

朋友们,

我正在使用以下代码获取 GPS 位置

这会导致两个问题

1) 当我的位置发生变化/我将手机从一个区域移动到另一个区域时,我没有得到更新的 gps 位置(纬度/经度)

2) 获取gps位置后,我的手机gps开启了如何关闭?

 double MyDeviceLatitude,MyDeviceLongitude;

public void GetGPSLocation()
{

 LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 

                       LocationListener myLocationListener = new CurrentLocationListener(); 

                       locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30, 30, myLocationListener);

                   Location   currentLocation = locationManager.getLastKnownLocation("gps"); 

if(currentLocation != null)
                       {

                       MyDeviceLatitude = currentLocation.getLatitude();
                       MyDeviceLongitude = currentLocation.getLongitude();
}else
{

 currentLocation = locationManager.getLastKnownLocation("network");
 MyDeviceLatitude = currentLocation.getLatitude();
 MyDeviceLongitude = currentLocation.getLongitude();



}



public class CurrentLocationListener implements LocationListener{

            public void onLocationChanged(Location argLocation) 
            {
                if (argLocation != null) 
                {
                    MyDeviceLatitude = argLocation.getLatitude();
                    MyDeviceLongitude = argLocation.getLongitude();
                }

            }
            public void onProviderDisabled(String provider) {
            }

            public void onProviderEnabled(String provider) {
            }

            public void onStatusChanged(String provider, int status, Bundle arg2) {
            }
            }

}

任何帮助将不胜感激。

【问题讨论】:

    标签: android


    【解决方案1】:

    UMMA 请检查这个使用广播接收器的类似帖子,这似乎可以解决您的问题Android: How to get location information from intent bundle extras when using LocationManager.requestLocationUpdates()

    【讨论】:

    • 示例不完整,所以我无法实现:(
    • @UMMA 您需要创建一个 LocationReceiver(扩展 BroadcastReceiver)并将其添加到您的清单中,如链接中所述。请阅读有关如何将此 BroadcastReceiver 与您的活动/服务集成的指南。您可以将获得的位置传递给您的活动/服务。
    猜你喜欢
    • 1970-01-01
    • 2013-05-06
    • 2016-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多