OpenLayers Geolocation in PyQt 5.9

后端 未结 2 1811
春和景丽
春和景丽 2020-12-12 02:46

I\'ve implemented a Website with a geolocation function and Button.

This Webpage gets displayed fine in a QwebEngineView (OSM Map too). The Webpage is loaded

相关标签:
2条回答
  • 2020-12-12 03:15

    Adding the following lines solved my Problems:

        self.ui.w3View.page().featurePermissionRequested.connect(self.permissionRequested)
    
    def permissionRequested(self, frame, feature):
        self.ui.w3View.page().setFeaturePermission(frame, feature, QtWebEngineWidgets.QWebEnginePage.PermissionGrantedByUser)
    

    Found it in this post and editing it to PyQt 5.9.

    0 讨论(0)
  • 2020-12-12 03:34

    The main problem is to enable the permissions, if you run in a browser like Firefox, Chrome, etc. will show you a popup asking you to accept or not the GeoLocation permission.

    In this case it must be enabled by code, for this the QWebEnginePage emits a signal every time authorization is required, it does this through the signal featurePermissionRequested, we connect it to some slot and we enable the permission with the function setFeaturePermission().

        self.ui.w3View..page().featurePermissionRequested.connect(self.onFeaturePermissionRequested)
    
    def onFeaturePermissionRequested(self, securityOrigin, feature):
        self.sender().setFeaturePermission(securityOrigin,
                                         QWebEnginePage.Geolocation,
                                         QWebEnginePage.PermissionGrantedByUser)
    

    Note: In linux I still have problems with the GeoClude provider, the error message is as follows:

    Failed to set Geoclue positioning requirements. Geoclue error: org.qtproject.QtDBus.Error.InvalidObjectPath

    0 讨论(0)
提交回复
热议问题