×
Namespaces

Variants
Actions
(Difference between revisions)

Reverse Geocoding in QML

From Nokia Developer Wiki
Jump to: navigation, search
mahbub_s60 (Talk | contribs)
(Mahbub s60 -)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix metadata and links)
 
(13 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Category:Qt Mobility]][[Category:Location]][[Category:Code Snippet]]
+
[[Category:Qt Mobility]][[Category:Code Snippet]][[Category:HERE Maps]]
{{ArticleMetaData <!-- v1.1 -->
+
{{ArticleMetaData <!-- v1.2 -->
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
+
|sourcecode= [[Media:mapqmlreversegeocode.zip]]
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
Line 7: Line 7:
 
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->  
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
+
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
|id= <!-- Article Id (Knowledge base articles only) -->
 
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|translated-by= <!-- [[User:XXXX]] -->
 
|translated-by= <!-- [[User:XXXX]] -->
|translated-from-title= <!-- Title only -->  
+
|translated-from-title= <!-- Title only -->
 
|translated-from-id= <!-- Id of translated revision -->
 
|translated-from-id= <!-- Id of translated revision -->
|review-by=<!-- After re-review: [[User:username]] -->
+
|review-by= <!-- After re-review: [[User:username]] -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|update-by= <!-- After significant update: [[User:username]]-->
 
|update-by= <!-- After significant update: [[User:username]]-->
 
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 
|update-timestamp= <!-- After significant update: YYYYMMDD -->
|creationdate= <!-- Format YYYYMMDD -->
+
|creationdate= 20120127
|author= <!-- Display as link [[User:username]] -->
+
|author= [[User:Mahbub s60]]
 
}}
 
}}
  
Line 29: Line 28:
 
Reverse geocoding is the opposite: finding an associated textual location such as a street address, from geographic coordinates. In this article and code snippet, we explain how we can get address of a place by reverse geocoding with Nokia map.
 
Reverse geocoding is the opposite: finding an associated textual location such as a street address, from geographic coordinates. In this article and code snippet, we explain how we can get address of a place by reverse geocoding with Nokia map.
  
==How to get address from coordinate==
+
==How to get address from coordinate==
We call reverseGeocode() method of QGeoSearchManager and pass the coordinate of the place that we are looking for. If we are interested to a place near by then we can use our device’s positioning system to get the current location and that can be passed to reverseGeocode() method as shown in the following snippet. geocodeFinished slot will be called when it has found the address.
+
We call {{Icode|reverseGeocode()}} method of {{Icode|QGeoSearchManager}} and pass the coordinate of the place that we are looking for. If we are interested to a place near by then we can use our device’s positioning system to get the current location and that can be passed to {{Icode|reverseGeocode()}} method as shown in the following snippet. {{Icode|geocodeFinished}} slot will be called when it has found the address.
<code cpp>
+
<code cpp-qt>
    QGeoSearchReply *reply = m_searchManager->reverseGeocode(m_geoCoordinate);   QObject::connect(reply, SIGNAL(finished()), this,SLOT(geocodeFinished()));
+
QGeoSearchReply *reply = m_searchManager->reverseGeocode(m_geoCoordinate);  
    QObject::connect(reply,SIGNAL(error(QGeoSearchReply::Error, QString)), this,SLOT(resultsError(QGeoSearchReply::Error, QString)));
+
QObject::connect(reply, SIGNAL(finished()), this,SLOT(geocodeFinished()));
 +
QObject::connect(reply,SIGNAL(error(QGeoSearchReply::Error, QString)), this,SLOT(resultsError(QGeoSearchReply::Error, QString)));
 
</code >
 
</code >
geocodeFinished has been implemented in the following code.
+
{{Icode|geocodeFinished}} has been implemented in the following code.
<code cpp>
+
<code cpp-qt>
  
 
void CLocationSource::geocodeFinished()
 
void CLocationSource::geocodeFinished()
Line 65: Line 65:
 
}
 
}
 
</code >
 
</code >
We need very thin QML code as most stuffs are done in Qt C++ side and that is brought to QML side by using qmlRegisterType() method.     
+
We need very thin QML code as most stuffs are done in Qt C++ side and that is brought to QML side by using {{Icode|qmlRegisterType()}} method.     
<code cpp>
+
<code cpp-qt>
 
         PositionSource {
 
         PositionSource {
 
             id: apositionSource
 
             id: apositionSource
Line 73: Line 73:
 
             // nmeaSource: "nmealog.txt"
 
             // nmeaSource: "nmealog.txt"
 
         }
 
         }
 
 
 
 
         CLocationSource
 
         CLocationSource
 
         {
 
         {
 
             id: positionSource
 
             id: positionSource
 
 
             onLonChanged:
 
             onLonChanged:
 
             {
 
             {
Line 88: Line 84:
 
                 console.log(" onLatChanged in QML")
 
                 console.log(" onLatChanged in QML")
 
             }
 
             }
 
 
             onAddressChanged:
 
             onAddressChanged:
 
             {
 
             {
Line 94: Line 89:
 
             }
 
             }
 
         }
 
         }
 
  
 
     Coordinate
 
     Coordinate
Line 122: Line 116:
 
</code >
 
</code >
  
 +
[[Category:Code Examples]]
  
 
== Examples ==
 
== Examples ==
Download the example for C7: [[Image:mapqmlreversegeocode.zip]]
+
Download the example for Nokia Belle: [[File:mapqmlreversegeocode.zip]][[Category:MeeGo Harmattan]] [[Category:Symbian]]

Latest revision as of 08:45, 24 April 2013

Article Metadata
Code ExampleCompatibility
Platform(s):
Symbian
Article
Created: mahbub_s60 (27 Jan 2012)
Last edited: hamishwillee (24 Apr 2013)


[edit] Introduction

Geocoding is the process of finding associated geographic coordinates (often expressed as latitude and longitude) from other geographic data, such as street addresses, or zip codes (postal codes). With geographic coordinates the features can be mapped and entered into Geographic Information Systems, or the coordinates can be embedded into media such as digital photographs via geotagging. Reverse geocoding is the opposite: finding an associated textual location such as a street address, from geographic coordinates. In this article and code snippet, we explain how we can get address of a place by reverse geocoding with Nokia map.

[edit] How to get address from coordinate

We call reverseGeocode() method of QGeoSearchManager and pass the coordinate of the place that we are looking for. If we are interested to a place near by then we can use our device’s positioning system to get the current location and that can be passed to reverseGeocode() method as shown in the following snippet. geocodeFinished slot will be called when it has found the address.

QGeoSearchReply *reply = m_searchManager->reverseGeocode(m_geoCoordinate); 
QObject::connect(reply, SIGNAL(finished()), this,SLOT(geocodeFinished()));
QObject::connect(reply,SIGNAL(error(QGeoSearchReply::Error, QString)), this,SLOT(resultsError(QGeoSearchReply::Error, QString)));

geocodeFinished has been implemented in the following code.

void CLocationSource::geocodeFinished()
{
QGeoSearchReply* reply = static_cast<QGeoSearchReply *>(sender());
 
if (reply->error() != QGeoSearchReply::NoError) {
// Errors are handled in a different slot (resultsError)
return;
}
 
QList<QGeoPlace> places = reply->places();
if (places.length() == 0)
{
 
// do something here
}
else
{
QGeoAddress address = places[0].address();
QString message = address.city() + ", " + address.country().toLower();
setAddress(message);
}
 
disconnect(reply, SIGNAL(finished()), this,SLOT(geocodeFinished()));
disconnect(reply,SIGNAL(error(QGeoSearchReply::Error, QString)), this,SLOT(resultsError(QGeoSearchReply::Error, QString)));
reply->deleteLater();
}

We need very thin QML code as most stuffs are done in Qt C++ side and that is brought to QML side by using qmlRegisterType() method.

        PositionSource {
id: apositionSource
updateInterval: 1000
active: false
// nmeaSource: "nmealog.txt"
}
CLocationSource
{
id: positionSource
onLonChanged:
{
console.log(" onLonChanged in QML")
}
onLatChanged:
{
console.log(" onLatChanged in QML")
}
onAddressChanged:
{
console.log(" Address has been changed")
}
}
 
Coordinate
{
id: mycordinate
latitude: positionSource.lat
longitude: positionSource.lon
}
 
Map
{
id: map
plugin : Plugin { name : "nokia" }
anchors.fill: parent; size.width: parent.width; size.height: parent.height; zoomLevel: 12
center: mycordinate
 
}
Column
{
Text {text: "Click on screen to swap positioningMethod: " }
Text {text: "<==== Position ====>"}
Text {text: "latitude: " + mycordinate.latitude}
Text {text: "longitude: " + mycordinate.longitude}
Text {text: "Address: " + positionSource.address}
}

[edit] Examples

Download the example for Nokia Belle: File:Mapqmlreversegeocode.zip

This page was last modified on 24 April 2013, at 08:45.
101 page views in the last 30 days.
×