Was ist die Authentifizierung von Location Services mit API Key?

651
0
02-06-2023 06:17 AM
Jan-Tschada
Esri Contributor
2 0 651

Der einfachste Weg direkten Zugriff auf die Location Services von ArcGIS Platform zu erhalten, ist die Verwendung eines API Keys. Beim Erstellen eines Qt Creator Projektes mit der ArcGIS Maps SDKs for Qt  - Vorlage wird ein Platzhalter für den entsprechenden API Key im Quellcode erzeugt. Man muss lediglich sich in das eigene Developer Dashboard bewegen, einen entsprechenden API Key anlegen und kann dann den Zugriff auf die Location Services verwalten. Der API Key wird einfach im Quellcode ersetzt, oder über einen Konfigurationsmechanismus eingelesen - z.B. über eine entsprechende Umgebungsvariable.

JanTschada_0-1675692591256.png

 

#include "ArcGISRuntimeEnvironment.h"
#include <QProcessEnvironment>

using namespace Esri::ArcGISRuntime;

///
/// \brief readApiKeyFromEnvironment
/// Reads the API key directly accessing the location services of ArcGIS Platform
/// using the current process environment.
/// The environment must contain a variable named 'arcgisruntime_api_key'.
///
static void readApiKeyFromEnvironment()
{
    QString apiKeyName = "arcgisruntime_api_key";
    QProcessEnvironment systemEnvironment = QProcessEnvironment::systemEnvironment();
    if (systemEnvironment.contains(apiKeyName))
    {
        QString apiKey = systemEnvironment.value(apiKeyName);
        ArcGISRuntimeEnvironment::setApiKey(apiKey);
    }
    else
    {
        qWarning() << "Use of Esri location services, including basemaps, requires "
            "you to authenticate with an ArcGIS identity or set the API Key property.";
    }
}

 

ArcGIS Developers API Keys 

Labels