Is there a typescript or javascript api for Geolocation - Get IP to Location Preview capability in the Azure Maps npm module azure-maps-rest

Viewed 336

There are a lot of options to this api and I am not finding this capability in the module? If it is not in there can it be added in the future?

The preview is here

The typescript API is here

1 Answers

Not currently. The services module wraps a subset of the services currently based on priority/popularity. Also there are some planned improvements to the geolocation API, so have been waiting for that.

Using this API from the browser is pretty easy though as you simply append the IP address and your subscription key to the service URL and use the fetch API in the browser to download the results. Here is a code block:

interface IpToLocationResponse {
    ipAddress: string;
    countryRegion: IpToLocationCountry;
    error: IpToLocationError;
}

interface IpToLocationCountry {
    isoCode: string
}

interface IpToLocationError {
    code: string;
    message: string;
}

public ipToLocation(subscriptionKey, ipAddress): Promise<IpToLocationResponse> {

    var request = `https://atlas.microsoft.com/geolocation/ip/json?subscription-key=${subscriptionKey}&api-version=1.0&ip=${ipAddress}`;

    return fetch(request)
    .then(r => {
        return r.json();
    });
}
Related