Qt的地理位置示例示例

时间:2011-05-13 09:25:23

标签: qt html5 google-maps qt4 geolocation

我可以获得Qt的地理定位样本吗?

我有一些地图样本,但不是地理位置样本。

2 个答案:

答案 0 :(得分:0)

这个link有一个例子。

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;
 }
};

答案 1 :(得分:-1)

<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>