QGIS API Documentation  3.23.0-Master (22c16f2067)
Public Member Functions | List of all members
QgsGoogleMapsGeocoder Class Reference

A geocoder which uses the Google Map geocoding API to retrieve results. More...

#include <qgsgooglemapsgeocoder.h>

Inheritance diagram for QgsGoogleMapsGeocoder:
Inheritance graph
[legend]

Public Member Functions

 QgsGoogleMapsGeocoder (const QString &apiKey, const QString &regionBias=QString())
 Constructor for QgsGoogleMapsGeocoder. More...
 
QString apiKey () const
 Returns the API key which will be used when accessing the Google Maps API. More...
 
QgsFields appendedFields () const override
 Returns a set of newly created fields which will be appended to existing features during the geocode operation. More...
 
Flags flags () const override
 Returns the geocoder's capability flags. More...
 
QList< QgsGeocoderResultgeocodeString (const QString &string, const QgsGeocoderContext &context, QgsFeedback *feedback=nullptr) const override
 Geocodes a string. More...
 
QgsGeocoderResult jsonToResult (const QVariantMap &json) const
 Converts a JSON result returned from the Google Maps service to a geocoder result object. More...
 
QString region () const
 Returns the optional region bias which will be used to prioritize results in a certain region. More...
 
QUrl requestUrl (const QString &address, const QgsRectangle &bounds=QgsRectangle()) const
 Returns the URL generated for geocoding the specified address. More...
 
void setApiKey (const QString &key)
 Sets the API key to use when accessing the Google Maps API. More...
 
void setEndpoint (const QString &endpoint)
 Sets a specific API endpoint to use for requests. More...
 
void setRegion (const QString &region)
 Sets the optional region bias which will be used to prioritize results in a certain region. More...
 
QgsWkbTypes::Type wkbType () const override
 Returns the WKB type of geometries returned by the geocoder. More...
 
- Public Member Functions inherited from QgsGeocoderInterface
virtual ~QgsGeocoderInterface ()=default
 
virtual QList< QgsGeocoderResultgeocodeFeature (const QgsFeature &feature, const QgsGeocoderContext &context, QgsFeedback *feedback=nullptr) const
 Geocodes a feature. More...
 

Additional Inherited Members

- Public Types inherited from QgsGeocoderInterface
enum class  Flag { GeocodesStrings = 1 << 0 , GeocodesFeatures = 1 << 1 }
 Capability flags for the geocoder. More...
 

Detailed Description

A geocoder which uses the Google Map geocoding API to retrieve results.

This geocoder utilizes the Google Maps "geocoding" API in order to geocode strings. The Google Maps service is not publicly available, and accordingly an API key must be first obtained from Google and specified when constructing this class.

Warning
The user is responsible for managing their Google Maps API key, and ensuring that the use of this geocoder does not exceed their usage limits! Excessive use of the Google Maps geocoder API can result in charges being applied to the API key holder.
Since
QGIS 3.18

Definition at line 40 of file qgsgooglemapsgeocoder.h.

Constructor & Destructor Documentation

◆ QgsGoogleMapsGeocoder()

QgsGoogleMapsGeocoder::QgsGoogleMapsGeocoder ( const QString &  apiKey,
const QString &  regionBias = QString() 
)

Constructor for QgsGoogleMapsGeocoder.

The apiKey argument must specify a valid Google Maps API key. All use of this geocoder will be associated with the specified key for Google's billing purposes!

Optionally, a regionBias can be specified to prioritize results in a certain region. The regionBias argument must be set to a two letter country code top-level domain value, e.g. "gb" for Great Britain.

Definition at line 35 of file qgsgooglemapsgeocoder.cpp.

Member Function Documentation

◆ apiKey()

QString QgsGoogleMapsGeocoder::apiKey ( ) const

Returns the API key which will be used when accessing the Google Maps API.

See also
setApiKey()

Definition at line 292 of file qgsgooglemapsgeocoder.cpp.

◆ appendedFields()

QgsFields QgsGoogleMapsGeocoder::appendedFields ( ) const
overridevirtual

Returns a set of newly created fields which will be appended to existing features during the geocode operation.

These fields will include any extra content returned by the geocoder, such as fields for accuracy of the match or correct attribute values.

Reimplemented from QgsGeocoderInterface.

Definition at line 49 of file qgsgooglemapsgeocoder.cpp.

◆ flags()

QgsGeocoderInterface::Flags QgsGoogleMapsGeocoder::flags ( ) const
overridevirtual

Returns the geocoder's capability flags.

Implements QgsGeocoderInterface.

Definition at line 44 of file qgsgooglemapsgeocoder.cpp.

◆ geocodeString()

QList< QgsGeocoderResult > QgsGoogleMapsGeocoder::geocodeString ( const QString &  string,
const QgsGeocoderContext context,
QgsFeedback feedback = nullptr 
) const
overridevirtual

Geocodes a string.

If implemented by the geocoder (i.e. flags() returns the QgsGeocoderInterface::Flag::GeocodesStrings flag), a list of matching results will be returned.

The optional feedback argument can be used to provider cancellation support.

Reimplemented from QgsGeocoderInterface.

Definition at line 72 of file qgsgooglemapsgeocoder.cpp.

◆ jsonToResult()

QgsGeocoderResult QgsGoogleMapsGeocoder::jsonToResult ( const QVariantMap &  json) const

Converts a JSON result returned from the Google Maps service to a geocoder result object.

Definition at line 223 of file qgsgooglemapsgeocoder.cpp.

◆ region()

QString QgsGoogleMapsGeocoder::region ( ) const

Returns the optional region bias which will be used to prioritize results in a certain region.

See also
setRegion()

Definition at line 302 of file qgsgooglemapsgeocoder.cpp.

◆ requestUrl()

QUrl QgsGoogleMapsGeocoder::requestUrl ( const QString &  address,
const QgsRectangle bounds = QgsRectangle() 
) const

Returns the URL generated for geocoding the specified address.

Definition at line 159 of file qgsgooglemapsgeocoder.cpp.

◆ setApiKey()

void QgsGoogleMapsGeocoder::setApiKey ( const QString &  key)

Sets the API key to use when accessing the Google Maps API.

All use of this geocoder will be associated with the specified key for Google's billing purposes!

See also
apiKey()

Definition at line 297 of file qgsgooglemapsgeocoder.cpp.

◆ setEndpoint()

void QgsGoogleMapsGeocoder::setEndpoint ( const QString &  endpoint)

Sets a specific API endpoint to use for requests.

This is for internal testing purposes only.

Definition at line 287 of file qgsgooglemapsgeocoder.cpp.

◆ setRegion()

void QgsGoogleMapsGeocoder::setRegion ( const QString &  region)

Sets the optional region bias which will be used to prioritize results in a certain region.

The region argument must be set to a two letter country code top-level domain value, e.g. "gb" for Great Britain.

See also
region()

Definition at line 307 of file qgsgooglemapsgeocoder.cpp.

◆ wkbType()

QgsWkbTypes::Type QgsGoogleMapsGeocoder::wkbType ( ) const
overridevirtual

Returns the WKB type of geometries returned by the geocoder.

If this is not known in advance then QgsWkbTypes::Unknown should be returned (e.g. in the case that a geocoder may return different geometry types depending on the quality of the match).

Reimplemented from QgsGeocoderInterface.

Definition at line 67 of file qgsgooglemapsgeocoder.cpp.


The documentation for this class was generated from the following files: