QtMobility.locationを使用した地図作成および地理位置情報モバイルアプリケーションの開発の概要

この投稿は、コンテスト「 Smart Posts for Smart Posts 」に参加しています



これまで地図作成および地理位置情報モバイルアプリケーションの開発に参加する必要がなかったため、この競争のトピックは、専門家としての成長と人間の通常の好奇心の両方の面で興味深いものになりました。 当然、私はQtQuickが主題を研究するタスクを大いに促進するのではないかと疑っていましたが 、彼は再び問題を解決するエレガントなシンプルさに喜んで驚きました。





QtMobility.locationについてです 。 ところで、スクリーンショットに示されているアプリケーションには、1ページ未満のQMLコードが含まれており、C ++の1行は含まれていません。








おそらく、伝統的な最小限の「Hello、World !!!」アプリケーションから始める価値があります。 ただし、この「Hello、World !!!」は通常とは多少異なります。 これはもはや、暗くて友好的なコンソールで新しくhatch化したヒナのきしみではなく、隣の庭に飛んだときの彼の小さな勝利の叫びです。 このように見えます(このアプリケーションのスクリーンショットは上にあります):

  1. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  2. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  3. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  4. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  5. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  6. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  7. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  8. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  9. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  10. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  11. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  12. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  13. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  14. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  15. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  16. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  17. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  18. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  19. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  20. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  21. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  22. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  23. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  24. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  25. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  26. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page



  27. import QtQuick 1.1 import QtMobility.location 1.2 Item { id: page anchors.fill: parent focus: true TitleBar { id: titleBar; appname: "Hello World" ; z: 5; width: parent.width; height: 40; opacity: 0.8 } Rectangle { id: dataArea anchors.top: titleBar.bottom anchors.bottom: parent.bottom width: parent.width color: "#343434" Map { id: map plugin: Plugin { name : "nokia" } anchors.fill: parent size.width: parent.width size.height: parent.height zoomLevel: 6 center: Coordinate {latitude: 55; longitude: 73.12} mapType: Map.StreetMap } // map } } // page





ここで私たちが興味を持っている主な要素は、もちろん、 Map要素です。 それについて詳しく説明します。 彼は地図の読み込みと表示を担当しています。 この要素の主な作業は、 Plugin要素で記述されたプラグインによって行われます。



centerプロパティ-表示されたマップの中心の座標。 マップ上の新しい場所に「ジャンプ」するには、 Map要素のcenterプロパティの値を変更するだけです。 map.pan(dx、dy)関数を使用すると、マップ内を突然移動できるだけでなく、スムーズに移動できます。 dx、dy-左/右シフト、前の位置からの相対的な上下\。



zoomLevelは、マップのスケールを担当します。 このプロパティの値を変更することにより、ズームイン/ズームアウトできます。 最小値と最大値は、 minimumZoomLevelプロパティmaximumZoomLevelプロパティから差し引かれます



mapTypeはマップタイプです。 次のタイプが利用可能です。

•Map.StreetMap

•Map.SatelliteMapDay

•Map.SatelliteMapNight

•Map.TerrainMap

•Map.HybridMap

•Map.TransitMap

•Map.GrayStreetMap

•Map.MobileStreetMap

•Map.MobileTerrainMap

•Map.MobileHybridMap

•Map.MobileTransitMap

•Map.MobileGrayStreetMap

正しく表示するには、カードの種類がもちろんプロバイダーによってサポートされている必要があります。



上記のスクリーンショットでは、マップタイプMap.StreetMapが使用されています。

下のスクリーンショット-Map.SatelliteMapDay








MapRectangle、MapCircle、MapText、MapImage、MapPolygon、MapPolylineなどのさまざまな要素を、 Map要素の子エンティティとしてマップに追加できます。 これらのアイテムは、指定した位置に自動的に表示されます。 これらは、マップ上にさまざまなラベルを設定し、ルート、エリア、および必要なすべてのものを表示するのに非常に便利です。

たとえば、これは、必要な位置で地図上にテキストを表示する方法です。

  1. MapText {
  2. id:テキスト
  3. 座標:座標{緯度:54.914; 経度:73.313}
  4. 色: 「黄色」
  5. テキスト: 「サマルカ」
  6. font.pixelSize:10
  7. }




または、このように-黄色の円を使用すると、マップ上の現在のユーザー座標をマークできます。

  1. MapCircle {
  2. id:userPosition
  3. 色: 「黄色」
  4. 半径:10
  5. センター:userPositionSource.position.coordinate
  6. }




しかし、ユーザーの座標をマークするには、まずそれらを見つける必要があります。 QtMobilityでは、これも基本的に行われます。 また、 QML PositionSource要素はこれを支援します。 これにより、現在の座標、高度、速度などに関する情報を取得できます。







次のコードは、この要素から何を取得する方法を示しています。

  1. Qt 4.7のインポート
  2. QtMobility.location 1.2のインポート
  3. 長方形{
  4. id:ページ
  5. 幅:350
  6. 高さ:350
  7. PositionSource {
  8. id:positionSource
  9. updateInterval:1000
  10. アクティブ: true
  11. // nmeaSource: "nmealog.txt"
  12. }
  13. 列{
  14. テキスト{text: "<==== PositionSource ====>" }
  15. テキスト{text: "positioningMethod:" + printableMethod(positionSource.positioningMethod)}
  16. テキスト{text: "nmeaSource:" + positionSource.nmeaSource}
  17. テキスト{text: "updateInterval:" + positionSource.updateInterval}
  18. テキスト{text: "active:" + positionSource.active}
  19. テキスト{text: "<====位置====>" }
  20. テキスト{text: "latitude:" + positionSource.position.coordinate.latitude}
  21. テキスト{text: "longitude:" + positionSource.position.coordinate.longitude}
  22. テキスト{text: "altitude:" + positionSource.position.coordinate.altitude}
  23. テキスト{text: "speed:" + positionSource.position.speed}
  24. テキスト{text: "timestamp:" + positionSource.position.timestamp}
  25. テキスト{text: "altitudeValid:" + positionSource.position.altitudeValid}
  26. テキスト{text: "longitudeValid:" + positionSource.position.longitudeValid}
  27. テキスト{text: "latitudeValid:" + positionSource.position.latitudeValid}
  28. テキスト{text: "speedValid:" + positionSource.position.speedValid}
  29. }
  30. function printableMethod(メソッド){
  31. if (method == PositionSource.SatellitePositioningMethod)
  32. return "Satellite" ;
  33. else if (method == PositionSource.NoPositioningMethod)
  34. 「利用不可」を 返す
  35. else if (method == PositionSource.NonSatellitePositioningMethod)
  36. 「非衛星」を 返す
  37. else if (method == PositionSource.AllPositioningMethods)
  38. 「すべて/複数」を 返す
  39. 「ソースエラー」を 返す ;
  40. }
  41. }











また、画面にすでに表示されているオブジェクトのグローバル座標を取得する方法にも興味がありました。 それは判明しました-QtMobilityでは、これも非常に簡単に行われます。 map.toCoordinate()関数は、オブジェクトの画面座標をグローバルに変換します。 画面上のオブジェクトに触れました-座標を取得しました:

  1. onPressed:{
  2. console.log( 'latitude =' +(map.toCoordinate(Qt.point(mouse.x、mouse.y)))。緯度);
  3. console.log( 'longitude =' +(map.toCoordinate(Qt.point(mouse.x、mouse.y)))。経度);
  4. }







結論として、 OVI Maps APIの知人について簡単に言及したいと思います 。 OVI Maps APIを使用すると、アプリケーションを使用して、名前やその他の多くのことで場所の検索を簡単に整理できます。 たとえば、次のスクリーンショットでは、ポイント「A」と「B」が設定されており、OVI Maps APIは1つのルートから別のルートを提供します。 その中のマップはJavaScriptによって管理されます。 ご存知のように、QMLの親友はJavaScriptであり、コードに直接埋め込むことができます。 したがって、QML-JavaScript-OVI Maps APIの組み合わせは、複雑な地図作成および地理位置情報モバイルアプリケーションを作成するための非常に強力なツールのように思えました。 そして、QtQuickはその力と優雅なシンプルさを再び実証しました。



OVI Maps APIプレイグラウンド:








All Articles