所以我_1075461已经使用这个资源作为开始:http://turbomanage.wordpress.com/2012/04/23/how-to-enable-geolocation-in-a-webview-android/并且我很好地复制了C#中所需的组件,但是在WebView中加载的页面只是在地理定位提示处于待处理状态时加载的灰色页面(不允许)也没有否认) .
我有所需的权限:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
这是我的webView用法
webvw = FindViewById<WebView>(Resource.Id.webView1);
webvw.SetWebViewClient(new GeoWebViewClient());
webvw.SetWebChromeClient(new GeoWebChromeClient());
webvw.Settings.JavaScriptCanOpenWindowsAutomatically = true;
webvw.Settings.DisplayZoomControls = true;
webvw.Settings.JavaScriptEnabled = true;
webvw.Settings.SetGeolocationEnabled(true);
webvw.LoadUrl("https://google-developers.appspot.com/maps/documentation/javascript/examples/full/map-geolocation");
自定义类
public class GeoWebChromeClient : WebChromeClient
{
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.ICallback callback)
{
// Always grant permission since the app itself requires location
// permission and the user has therefore already granted it
callback.Invoke(origin, false, false);
}
}
public class GeoWebViewClient : WebViewClient
{
public bool shouldOverrideUrlLoading(WebView view, string url)
{
// When user clicks a hyperlink, load in the existing WebView
view.LoadUrl(url);
return true;
}
}
有没有人有什么建议?
谢谢
2 回答
您在代码中缺少
override
关键字:如果您在桌面浏览器上加载此页面,
您只会看到您描述的灰色页面 .
你必须设置纬度(44.433106)和经度(26.103687)的值,这里有两个例子:
更多信息:Google Maps Android API v2