【发布时间】:2019-10-23 13:27:51
【问题描述】:
我在 GWT JSNI(javascript 本机接口)中使用了 navigator.geolocation(),如下所示,以前效果很好,但最近不行。
private native void getGeolocation()/*-{
// Using HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
console.log('Pos: ' + pos);
}, function() {
console.log('error geolocation service');
});
} else {
// Browser doesn't support Geolocation
console.log('geolocation not support');
}
}-*/;
在浏览器未要求我提供位置权限的情况下,我将获得“错误地理定位服务”日志。但是,如果我直接在控制台执行这部分JS代码,那么浏览器会要求位置权限。
似乎 navigator.geolocation 在 JSNI 中不起作用。还是我错过了什么?
谢谢
【问题讨论】:
-
您使用的是 https 吗?在大多数浏览器中,位置在 http 中不起作用。
-
你试过
$wnd.navigator.geolocation吗? (和$wnd.console顺便说一句)
标签: html gwt geolocation navigator jsni