I have used the navigator.geolocation() in the GWT JSNI(javascript native interface) as below and it worked well before, but it does not recently.
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');
}
}-*/;
I will get the 'error geolocation service' log without the browser asked me for the location permission. However, if I executed the part of the JS code in the console directly, the browser will then ask for the location permission.
It seems that the navigator.geolocation does not work in the JSNI. Or did I miss anything there?
Thanks
You can try to use GTW's Geolocation. It is still experimental API but I think it's better than using JSNI.