LCOV - code coverage report
Current view: top level - core/geocoding - qgsgooglemapsgeocoder.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 1 0.0 %
Date: 2021-04-10 08:29:14 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :   qgsgooglemapsgeocoder.h
       3                 :            :   ---------------
       4                 :            :   Date                 : November 2020
       5                 :            :   Copyright            : (C) 2020 by Nyall Dawson
       6                 :            :   Email                : nyall dot dawson at gmail dot com
       7                 :            :  ***************************************************************************
       8                 :            :  *                                                                         *
       9                 :            :  *   This program is free software; you can redistribute it and/or modify  *
      10                 :            :  *   it under the terms of the GNU General Public License as published by  *
      11                 :            :  *   the Free Software Foundation; either version 2 of the License, or     *
      12                 :            :  *   (at your option) any later version.                                   *
      13                 :            :  *                                                                         *
      14                 :            :  ***************************************************************************/
      15                 :            : 
      16                 :            : #ifndef QGSGOOGLEMAPSGEOCODER_H
      17                 :            : #define QGSGOOGLEMAPSGEOCODER_H
      18                 :            : 
      19                 :            : #include "qgis_core.h"
      20                 :            : #include "qgsgeocoder.h"
      21                 :            : 
      22                 :            : #include <QMutex>
      23                 :            : 
      24                 :            : /**
      25                 :            :  * \ingroup core
      26                 :            :  * \brief A geocoder which uses the Google Map geocoding API to retrieve results.
      27                 :            :  *
      28                 :            :  * This geocoder utilizes the Google Maps "geocoding" API in order to geocode
      29                 :            :  * strings. The Google Maps service is not publicly available, and accordingly
      30                 :            :  * an API key must be first obtained from Google and specified when constructing
      31                 :            :  * this class.
      32                 :            :  *
      33                 :            :  * \warning The user is responsible for managing their Google Maps API key, and ensuring
      34                 :            :  * that the use of this geocoder does not exceed their usage limits! Excessive use
      35                 :            :  * of the Google Maps geocoder API can result in charges being applied to the API key
      36                 :            :  * holder.
      37                 :            :  *
      38                 :            :  * \since QGIS 3.18
      39                 :            : */
      40                 :          0 : class CORE_EXPORT QgsGoogleMapsGeocoder : public QgsGeocoderInterface
      41                 :            : {
      42                 :            : 
      43                 :            :   public:
      44                 :            : 
      45                 :            :     /**
      46                 :            :      * Constructor for QgsGoogleMapsGeocoder.
      47                 :            :      *
      48                 :            :      * The \a apiKey argument must specify a valid Google Maps API key. All use of this
      49                 :            :      * geocoder will be associated with the specified key for Google's billing purposes!
      50                 :            :      *
      51                 :            :      * Optionally, a \a regionBias can be specified to prioritize results in a certain region.
      52                 :            :      * The \a regionBias argument must be set to a two letter country code top-level domain value,
      53                 :            :      * e.g. "gb" for Great Britain.
      54                 :            :      */
      55                 :            :     QgsGoogleMapsGeocoder( const QString &apiKey, const QString &regionBias = QString() );
      56                 :            : 
      57                 :            :     Flags flags() const override;
      58                 :            :     QgsFields appendedFields() const override;
      59                 :            :     QgsWkbTypes::Type wkbType() const override;
      60                 :            :     QList< QgsGeocoderResult > geocodeString( const QString &string, const QgsGeocoderContext &context, QgsFeedback *feedback = nullptr ) const override;
      61                 :            : 
      62                 :            :     /**
      63                 :            :      * Returns the URL generated for geocoding the specified \a address.
      64                 :            :      */
      65                 :            :     QUrl requestUrl( const QString &address, const QgsRectangle &bounds = QgsRectangle() ) const;
      66                 :            : 
      67                 :            :     /**
      68                 :            :      * Converts a JSON result returned from the Google Maps service to a geocoder result object.
      69                 :            :      */
      70                 :            :     QgsGeocoderResult jsonToResult( const QVariantMap &json ) const;
      71                 :            : 
      72                 :            :     /**
      73                 :            :      * Sets a specific API \a endpoint to use for requests. This is for internal testing purposes only.
      74                 :            :      */
      75                 :            :     void setEndpoint( const QString &endpoint );
      76                 :            : 
      77                 :            :     /**
      78                 :            :      * Returns the API key which will be used when accessing the Google Maps API.
      79                 :            :      *
      80                 :            :      * \see setApiKey()
      81                 :            :      */
      82                 :            :     QString apiKey() const;
      83                 :            : 
      84                 :            :     /**
      85                 :            :      * Sets the API \a key to use when accessing the Google Maps API.
      86                 :            :      *
      87                 :            :      * All use of this geocoder will be associated with the specified key for Google's billing purposes!
      88                 :            :      *
      89                 :            :      * \see apiKey()
      90                 :            :      */
      91                 :            :     void setApiKey( const QString &key );
      92                 :            : 
      93                 :            :     /**
      94                 :            :      * Returns the optional region bias which will be used to prioritize results in a certain region.
      95                 :            :      *
      96                 :            :      * \see setRegion()
      97                 :            :      */
      98                 :            :     QString region() const;
      99                 :            : 
     100                 :            :     /**
     101                 :            :      * Sets the optional \a region bias which will be used to prioritize results in a certain region.
     102                 :            :      *
     103                 :            :      * The \a region argument must be set to a two letter country code top-level domain value,
     104                 :            :      * e.g. "gb" for Great Britain.
     105                 :            :      *
     106                 :            :      * \see region()
     107                 :            :      */
     108                 :            :     void setRegion( const QString &region );
     109                 :            : 
     110                 :            :   private:
     111                 :            : 
     112                 :            :     QString mApiKey;
     113                 :            :     QString mRegion;
     114                 :            :     QString mEndpoint;
     115                 :            : 
     116                 :            :     static QReadWriteLock sMutex;
     117                 :            : 
     118                 :            : };
     119                 :            : 
     120                 :            : #endif // QGSGOOGLEMAPSGEOCODER_H

Generated by: LCOV version 1.14