【问题标题】:Can't get location on Samsung Galaxy Tab 2 & Note无法在三星 Galaxy Tab 2 和 Note 上获取位置
【发布时间】:2013-04-12 06:57:16
【问题描述】:

我使用此代码获取位置:

final LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

        final Criteria locationCritera = new Criteria();
        locationCritera.setAccuracy(Criteria.ACCURACY_COARSE);
        locationCritera.setAltitudeRequired(false);
        locationCritera.setBearingRequired(false);
        locationCritera.setCostAllowed(true);
        locationCritera.setPowerRequirement(Criteria.NO_REQUIREMENT);

        final String providerName = locationManager.getBestProvider(locationCritera, true);

        if (providerName != null && locationManager.isProviderEnabled(providerName)) {
            locationManager.requestLocationUpdates(providerName, 20000, 100, this);
        } else {
            Toast.makeText(this, "GPS turned off!", Toast.LENGTH_LONG).show();
            final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }

ACCESS_FINE_LOCATION 和 ACCESS_COARSE_LOCATION 权限都在清单中定义。

网络和 GPS 都已打开,但我只使用参数“network”(一次)调用 onProviderEnabled。但相同的代码在 4.0 模拟器和 Onda 4.1 Tab 上运行良好。 为什么?

【问题讨论】:

  • 根据我的经验,有些设备有时接收 GPS 响应的速度非常慢。室内也无济于事。
  • 我在 Galaxy Tab 2 上遇到了同样的问题。我使用 getLocationManager().getLastKnownLocation(provider) 至少向用户展示了一些内容。

标签: android samsung-mobile android-location


【解决方案1】:

我有一个 GPS 示例。也许您可以将其用作参考: 例如here:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 2013-10-23
    相关资源
    最近更新 更多