我试图在GWT项目中获取用户的凝聚位置坐标,但即使使用18000(3分钟)的超时值,我总是会出现超时错误。我甚至不能在devmode中获得chrome的任何权限弹出窗口?
Geolocation geoLoc = Geolocation.getIfSupported();
if(geoLoc != null){
log.info("Geolocation is supported!");
Geolocation.PositionOptions options = new Geolocation.PositionOptions();
options.setMaximumAge(0);
options.setTimeout(18000);
options.setHighAccuracyEnabled(false);
geoLoc.getCurrentPosition(new Callback<Position, PositionError>() {
@Override
public void onSuccess(Position result) { // never called
Coordinates coords = result.getCoordinates();
final double lat = coords.getLatitude();
final double lng = coords.getLongitude();
log.info("Coordinates: (" + lat + ", " + lng + ")");
}
@Override
public void onFailure(PositionError error) { // always called
String message = "";
switch (error.getCode()) {
case PositionError.UNKNOWN_ERROR:
message = "Unknown Error";
break;
case PositionError.PERMISSION_DENIED:
message = "Permission Denied";
break;
case PositionError.POSITION_UNAVAILABLE:
message = "Position Unavailable";
break;
case PositionError.TIMEOUT:
message = "Time-out";
break;
default:
message = "Unknown error code.";
}
log.error("Can't Get Current Position: " + message); // ... Time-out
}
}, options);
}