2

我尝试了 hablitar 的 GPS 定位功能,将其放在清单 android 中:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

并将 webview 设置如下:

setGeolocationEnabled(true);

但仍然无法正常工作。我应该怎么做才能让它工作?我是新手。

4

1 回答 1

2

您需要开始在代码中请求 GPS 更新。

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

LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
                              // Called when a new location is found by the location provider.
    }
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1000, locationListener);

然后,您可以获取您收到的 GPS 值并通过 URL 将它们传递给 webview

于 2013-08-06T11:43:36.280 回答