Serial-Studio/libs/QMapControl/html/gps_8cpp-example.html
2021-12-06 10:56:03 -06:00

96 lines
5.1 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>QMapControl: gps.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.9 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<h1>gps.cpp</h1>This sample application uses GPS data from the gllin service, which you have to start manually before using this application. The file /tmp/nmeaNP is read in for the posiitons.<p>
The application receives positions from the GPS_Neo class and writes it into a label. You can toggle a button to set the view to the received coordinate.<p>
You can find this example here: MapAPI/Samples/GPS <div align="center">
<img src="sample_gps.png" alt="sample_gps.png">
<p><strong>screenshot</strong></p></div>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a href="http://3rdparty.downloads.openmoko.org">http://3rdparty.downloads.openmoko.org</a></dd></dl>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include "gps.h"</span>
GPS::GPS()
{
<span class="comment">// create MapControl</span>
mc = <span class="keyword">new</span> MapControl(QSize(480,640));
<span class="comment">// ImageManager::instance()-&gt;setProxy("www-cache", 8080);</span>
<span class="comment">// create MapAdapter to get maps from</span>
TileMapAdapter* mapadapter = <span class="keyword">new</span> TileMapAdapter(<span class="stringliteral">"tile.openstreetmap.org"</span>, <span class="stringliteral">"/%1/%2/%3.png"</span>, 256, 0, 17);
<span class="comment">// create a layer with the mapadapter and type MapLayer</span>
Layer* l = <span class="keyword">new</span> Layer(<span class="stringliteral">"Custom Layer"</span>, mapadapter, Layer::MapLayer);
<span class="comment">// add Layer to the MapControl</span>
mc-&gt;addLayer(l);
<span class="comment">// display the MapControl in the application</span>
QHBoxLayout* layout = <span class="keyword">new</span> QHBoxLayout;
layout-&gt;addWidget(mc);
setLayout(layout);
<span class="comment">// create buttons as controls for zoom</span>
QPushButton* zoomin = <span class="keyword">new</span> QPushButton(<span class="stringliteral">"+"</span>);
QPushButton* zoomout = <span class="keyword">new</span> QPushButton(<span class="stringliteral">"-"</span>);
followgps = <span class="keyword">new</span> QPushButton(<span class="stringliteral">"F"</span>);
followgps-&gt;setCheckable(<span class="keyword">true</span>);
gpsposition = <span class="keyword">new</span> QLabel();
zoomin-&gt;setMaximumWidth(50);
zoomout-&gt;setMaximumWidth(50);
followgps-&gt;setMaximumWidth(50);
gpsposition-&gt;setFont(QFont(<span class="stringliteral">"Arial"</span>, 10));
connect(zoomin, SIGNAL(clicked(<span class="keywordtype">bool</span>)),
mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(<span class="keywordtype">bool</span>)),
mc, SLOT(zoomOut()));
<span class="comment">// add zoom buttons to the layout of the MapControl</span>
QVBoxLayout* innerlayout = <span class="keyword">new</span> QVBoxLayout;
innerlayout-&gt;addWidget(zoomin);
innerlayout-&gt;addWidget(zoomout);
innerlayout-&gt;addWidget(followgps);
innerlayout-&gt;addWidget(gpsposition);
mc-&gt;setLayout(innerlayout);
GPS_Neo* gm = <span class="keyword">new</span> GPS_Neo();
connect(gm, SIGNAL(new_position(<span class="keywordtype">float</span>, QPointF)),
<span class="keyword">this</span>, SLOT(updatePosition(<span class="keywordtype">float</span>, QPointF)));
gm-&gt;start();
}
GPS::~GPS()
{
}
<span class="keywordtype">void</span> GPS::updatePosition(<span class="keywordtype">float</span> time, QPointF coordinate)
{
gpsposition-&gt;setText(QString::number(time) + <span class="stringliteral">" / "</span> + QString::number(coordinate.x()) + <span class="stringliteral">" / "</span> + QString::number(coordinate.y()));
<span class="keywordflow">if</span> (followgps-&gt;isChecked())
{
mc-&gt;setView(coordinate);
}
}
</pre></div> </div>
<hr size="1"><address style="text-align: right;"><small>Generated on Wed Jul 29 12:38:09 2009 for QMapControl by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
</body>
</html>