azure.maps.geolocation.aio package¶
-
class
azure.maps.geolocation.aio.
MapsGeolocationClient
(credential: Union[azure.core.credentials.AzureKeyCredential, azure.core.credentials_async.AsyncTokenCredential], **kwargs: Any)[source]¶ Azure Maps Geolocation REST APIs.
- Parameters
credential (AsyncTokenCredential or AzureKeyCredential) – Credential needed for the client to connect to Azure.
- Keyword Arguments
client_id (str) – Specifies which account is intended for usage with the Azure AD security model. It represents a unique ID for the Azure Maps account.
api_version (str) – The API version of the service to use for requests. It defaults to the latest service version. Setting to an older version may result in reduced feature compatibility.
Example:
from azure.core.credentials import AzureKeyCredential from azure.maps.geolocation.aio import MapsGeolocationClient subscription_key = os.getenv("AZURE_SUBSCRIPTION_KEY") maps_geolocation_client = MapsGeolocationClient(credential=AzureKeyCredential(subscription_key))
from azure.identity.aio import DefaultAzureCredential from azure.maps.geolocation.aio import MapsGeolocationClient credential = DefaultAzureCredential() maps_client_id = os.getenv("AZURE_MAPS_CLIENT_ID") maps_geolocation_client = MapsGeolocationClient(client_id=maps_client_id, credential=credential)
-
async
get_country_code
(ip_address: str, **kwargs: Any) → azure.maps.geolocation.models._models.CountryRegionResult[source]¶ This service will return the ISO country code for the provided IP address. Developers can use this information to block or alter certain content based on geographical locations where the application is being viewed from.
- Parameters
ip_address (str) – The IP address. Both IPv4 and IPv6 are allowed. Required.
- Returns
CountryRegionResult
- Return type
- Raises
Example:
from azure.core.credentials import AzureKeyCredential from azure.maps.geolocation.aio import MapsGeolocationClient maps_geolocation_client = MapsGeolocationClient(credential=AzureKeyCredential(subscription_key)) async with maps_geolocation_client: result = await maps_geolocation_client.get_country_code(ip_address="2001:4898:80e8:b::189") print("Get Country code with Geolocation:") print(result.iso_code)