-
Notifications
You must be signed in to change notification settings - Fork 0
/
locator.cpp
46 lines (38 loc) · 1.28 KB
/
locator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "locator.h"
Locator::Locator(QObject *parent) : QObject(parent)
{
m_source = QGeoPositionInfoSource::createDefaultSource(this);
if (m_source) {
connect(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(positionAcquired(QGeoPositionInfo)));
QMap<QString,QVariant> params;
params["here.app_id"] = "YcFcRULoKXQ7uFyyUFXi";
params["here.token"] = "RrY07ZqUc93icAWoP0FDIg";
m_provider = new QGeoServiceProvider("here", params);
m_searcher = m_provider->geocodingManager();
connect(m_searcher,&QGeoCodingManager::finished, this, &Locator::addressAcquired);
connect(m_searcher,&QGeoCodingManager::error, this, &Locator::error);
}
}
void Locator::addressAcquired()
{
QList<QGeoLocation> locations = data->locations();
if(locations.size()>0){
emit addressUpdatedView(locations[0].address().city());
}
m_source->stopUpdates();
}
void Locator::error()
{
qDebug() << "ERROR" << endl;
}
void Locator::startLocation()
{
m_source->startUpdates();
}
void Locator::positionAcquired(const QGeoPositionInfo &info)
{
qDebug() << "poition update:" << info ;
data = m_searcher->reverseGeocode(info.coordinate());
emit positionUpdatedView(info.coordinate());
}