How to generate city details based on IP?

Anonymous
2023-01-16T12:07:17.37+00:00

Hi Team

Please can someone suggest to me how we can generate city-based details using the IP address?

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
747 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Sreeju Nair 12,371 Reputation points
    2023-01-16T12:46:37.61+00:00

    Based on my best knowledge, Azure Maps Doesn't offer IP to City mapping. As of now, Azure offers IP-to-country mapping.

    https://learn.microsoft.com/en-us/rest/api/maps/geolocation/get-ip-to-location?tabs=HTTP

    So the IP Address to Location Result shall give the following information

    https://learn.microsoft.com/en-us/rest/api/maps/geolocation/get-ip-to-location?tabs=HTTP#ipaddresstolocationresult

    For IP to City, there are third-party services available. Some of them are given below.

    https://ipinfo.io/

    https://apilayer.com/marketplace/ip_to_location-api

    Hope this helps

    2 people found this answer helpful.

  2. QuantumCache 20,271 Reputation points
    2023-03-10T00:24:42.12+00:00

    Hello,

    Geolocation - Get IP To Location

    You can use Azure Maps to obtain city-based details using an IP address. Azure Maps provides a REST API called "IP Address to Location" that allows you to get the geolocation of an IP address, including the city. Here are the steps to achieve this:

    1. First, you need to sign up for an Azure Maps account and get an API key. You can sign up for a free account that allows up to 250,000 transactions per month.
    2. Next, you can call the "IP Address to Location" API using the following URL:

    https://atlas.microsoft.com/ipAddress/{ipAddress}?subscription-key={subscriptionKey}&api-version=1.0&verbose=true

    Replace {ipAddress} with the IP address you want to get the details for and {subscriptionKey} with your Azure Maps subscription key.

    1. The API returns a JSON response that includes the geolocation details of the IP address, including the city. Here is an example response:
    {
        "type": "Point",
        "coordinates": [
            -122.33207,
            47.60621
        ],
        "properties": {
            "city": "Seattle",
            "state": "Washington",
            "country": "United States",
            "postalCode": "98101",
            "query": "104.44.194.72"
        }
    }
    
    

    As you can see, the response includes the city ("Seattle") in the "properties" section.

    1. You can then parse the JSON response and extract the city name to use it in your application.

    Note that the accuracy of the geolocation details obtained from an IP address may not always be 100% accurate, but it should be sufficient for most use cases.


  3. rbrundritt 18,686 Reputation points Microsoft Employee
    2023-06-06T14:14:36.1266667+00:00

    As noted in some of the comments, Azure Maps Geolocation API only provides IP Address locations to country level at this time. I don't believe there is any Azure service that provides city level accurate IP Address to location information. There are non-Microsoft services available in the Azure Marketplace that do provide this functionality, such as this one: https://azuremarketplace.microsoft.com/en-us/marketplace/apps/fastah.ip_location_api_01?tab=Overview

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.