Qt 的地理定位示例

发布于 2024-11-07 04:14:29 字数 52 浏览 1 评论 0原文

我可以获得 Qt 的地理定位示例吗?

我有一些地图样本,但没有地理定位样本。

Can I get a geolocation sample for the Qt?

I have some map samples, but not a geolocation one.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

银河中√捞星星 2024-11-14 04:14:29

链接有一个示例。

class MyClass : public QObject
{
 Q_OBJECT
 public:
 MyClass(QObject *parent = 0)
     : QObject(parent)
 {
     QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this);
     if (source) {
         connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
                 this, SLOT(positionUpdated(QGeoPositionInfo)));
         source->startUpdates();
     }
 }

private slots:
 void positionUpdated(const QGeoPositionInfo &info)
 {
     qDebug() << "Position updated:" << info;
 }
};

This link has an example.

class MyClass : public QObject
{
 Q_OBJECT
 public:
 MyClass(QObject *parent = 0)
     : QObject(parent)
 {
     QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this);
     if (source) {
         connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
                 this, SLOT(positionUpdated(QGeoPositionInfo)));
         source->startUpdates();
     }
 }

private slots:
 void positionUpdated(const QGeoPositionInfo &info)
 {
     qDebug() << "Position updated:" << info;
 }
};
风启觞 2024-11-14 04:14:29
<script>
    function success(position) {
        var position={"coords":{"latitude":"18.520469","longitude":"73.856621"}};

        var mapcanvas = document.createElement('div');
        mapcanvas.id = 'mapcanvas';
        mapcanvas.style.height = '400px';
        mapcanvas.style.width = '560px';

        document.querySelector('article').appendChild(mapcanvas);

        var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
        var myOptions = {
            zoom: 15,
            center: latlng,
            mapTypeControl: false,
            navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);

        var marker = new google.maps.Marker({
            position: latlng,
            map: map,
            title:"You are here!"
        });
    }

    function error(msg) {
        // console.log(arguments);
    }

    if (navigator.geolocation) {
        //navigator.geolocation.getCurrentPosition(success, error);
    } else {
        error('not supported');
    }
    success("position");

</script>
<script>
    function success(position) {
        var position={"coords":{"latitude":"18.520469","longitude":"73.856621"}};

        var mapcanvas = document.createElement('div');
        mapcanvas.id = 'mapcanvas';
        mapcanvas.style.height = '400px';
        mapcanvas.style.width = '560px';

        document.querySelector('article').appendChild(mapcanvas);

        var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
        var myOptions = {
            zoom: 15,
            center: latlng,
            mapTypeControl: false,
            navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);

        var marker = new google.maps.Marker({
            position: latlng,
            map: map,
            title:"You are here!"
        });
    }

    function error(msg) {
        // console.log(arguments);
    }

    if (navigator.geolocation) {
        //navigator.geolocation.getCurrentPosition(success, error);
    } else {
        error('not supported');
    }
    success("position");

</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文