如何创建 android webview 将我的位置共享到网站?
在我的简单 Android 应用程序中,我创建了一个 webview 并放置了一个要加载的 URL。该链接需要共享我的位置。在我的代码中,我给出了如下的 webview 设置:
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setGeolocationEnabled(true);
和自定义 WebChromeClient
webview.setWebChromeClient(new GeoClient());
class GeoClient extends WebChromeClient {
@Override
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
super.onGeolocationPermissionsShowPrompt(origin, callback);
Log.d("geolocation permission", "permission >>>"+origin);
callback.invoke(origin, true, false);
}
}
但该链接仍然没有在网络中的谷歌地图上显示我的位置。当我在 Android 默认浏览器中加载该网址时,它会显示我当前的位置。我如何将我的位置分享到该链接?有人请帮我解决这个问题。提前致谢!!
In my simple android application, I have created a webview and put an URL to be loaded. The link needs my location to be shared. In my code i have given webview settings as follows:
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setGeolocationEnabled(true);
and custom WebChromeClient
webview.setWebChromeClient(new GeoClient());
class GeoClient extends WebChromeClient {
@Override
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
super.onGeolocationPermissionsShowPrompt(origin, callback);
Log.d("geolocation permission", "permission >>>"+origin);
callback.invoke(origin, true, false);
}
}
But the link still didn't show my location on the google map in the web. When i load that url in the android default browser it shows my current location. How can i share my location to the that link? Someone please help me out of this. Thanks in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试不要调用
super.onGeolocationPermissionsShowPrompt()
。股票浏览器不这样做。Try not calling
super.onGeolocationPermissionsShowPrompt()
. The stock browser don't do it.这段代码对我有用:)
This code works for me :)