0

我正在尝试在三星 Galaxy Grand 上运行我的应用程序,但它没有显示我当前的位置。

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

    // Creating a criteria object to retrieve provider
    Criteria criteria = new Criteria();

    // Getting the name of the best provider
    String provider = locationManager.getBestProvider(criteria, true);

    System.out.println("provider => " + provider);

    // Getting Current Location
    Location location = locationManager.getLastKnownLocation(provider);
    System.out.println("location  " + location);

但总是这一行返回 null locationManager.getLastKnownLocation(provider); 但这个应用程序在索尼和 lg等其他手机上运行良好。

我尝试了很多链接,但仍然是同样的问题。

getLastKnownLocation() 总是返回 null,所有提供者都是 DummyLocationProvider

Android LocationManager.getLastKnownLocation() 返回 null

返回空值的网络提供商和 GPS 提供商

允许

<permission
    android:name="xx.xxx.xxx.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="xicom.biz.perdiem.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />


<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<application android:label="@string/app_name" >
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyccccccccbvxcbpmFLAZwalBGM" />
......
4

1 回答 1

1

简而言之,检查这个答案

要以编程方式启动您的应用程序以获取“当前位置”,请在调用之前运行以下代码getLastKnownLocation

YOUR_APPLICATION_CONTEXT.getLocationManager().requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 0, new LocationListener() {
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
    @Override
    public void onProviderEnabled(String provider) {
    }
    @Override
    public void onProviderDisabled(String provider) {
    }
    @Override
    public void onLocationChanged(final Location location) {
    }
});

修复 GPSTracker 问题的一些建议可能是将其设置为 1 分钟 1 米

private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 1;
private static final long MIN_TIME_BW_UPDATES = 1000 * 60 ;
于 2013-10-14T07:23:04.193 回答