Guides
Last Updated Aug 04, 2023

Determining Geolocations and IP Addresses in Google Maps

Elizabeth (Lizzie) Shipton

Table of Contents:

Get your free
API
key now
4.8 from 1,863 votes
See why the best developers build on Abstract
START FOR FREE
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required
Get your free
IP Geolocation API
key now
4.8 from 1,863 votes
See why the best developers build on Abstract
START FOR FREE
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required

Your IP address is a string of numbers that identifies your computer to the world wide web. Every computer has a separate and unique IP that is used when the computer sends and receives network requests. Think of your IP address as your computer’s home address. While your IP address can’t reveal anything personal about you like your age, sex, or preferences, it can be used to look up geographic information like your location.

IP addresses identify you to the network

IP Geolocation is the process of determining the geographic location of an IP address. The information you get back could be as broad as what country the IP address is in, to as specific as a zipcode or a pair of coordinates.

There are several methods for determining the geolocation of an IP address. One of the most often used methods is the Google Map Geolocation API. Google Maps is considered to be some of the best mapping software available, and the API is free to use up to a point.

Related: How to add IP geolocation to your website

Let’s send your first free
API
IP Geolocation API
call
See why the best developers build on Abstract
Get your free api

Unfortunately, the Google Map Geolocation API console is cumbersome and confusing to use. Getting started with the Google Maps Geolocation API requires creating a Developer account in the Google Cloud, defining a new project, and entering billing information. It is not easy and there are a lot of hurdles in the way of setting up a simple test for app development.

Related: Explore IP Geolocation on an Interactive Map

Additionally, the information returned by the Google API is not necessarily the information you might want to use in your app. Google returns a lot of information about cell phone towers, WiFi nodes, and radio types, but no information about the country, city, postcode, or other useful information.

How Does the Google Map Geolocation API work? 

The Google Maps Geolocation API is primarily meant to be used without an IP address. It is able to look up the latitude and longitude of a mobile client based on that device’s proximity to cell phone towers and WiFi nodes. The Maps API does not require an IP address to look up a device’s location.

 

The Maps Api powers location sharing

When you use Google Map IP address geolocation in your app, you send a POST request to Google’s servers. In the request body, you can include an array of nearby cell phone towers or WiFi access points, which you could pull from the device’s internal network software. 

Google will use the provided information to triangulate the device’s position and send back a pair of latitude and longitude coordinates, along with accuracy information. If no cell tower or WiFi information is provided, the API will fall back to using the device’s IP address.

Get the location of any IP with an up-to-date API serving data for city, region, and country.

What Does Google Maps IP Reveal About a User?

The location information that the Maps API returns about a user is limited. It’s meant to be used to show the device’s position on a map, not to provide information like country, city, or zip code. The response object that is sent back looks like this:


{
  "location": {
    "lat": 37.421875199999995,
    "lng": -122.0851173
  },
  "accuracy": 120
}

The accuracy field represents a radius, in meters, around the given location. If the location is estimated based on the device’s IP address alone, this radius can be quite large. 

When this happens, it indicates that the device is out of range of cell phone towers or WiFi access points, or that none of the provided points were valid or recognized. In this case, the location cannot be accurately estimated. 

To test this, try setting the considerIp option in your request object to false. This will prevent Google from falling back to the IP address. If you get a 404 response, you’ve confirmed that the device is out of range of cell towers or WiFi.

How Are Geolocation Requests Sent?

Geolocation requests to the Maps API are sent using a POST request and JSON request object. In order to make a request, you need an API key, which you can get by creating a Google Developer account, setting up a project, and adding a billing method.

Google will not charge you until you’ve exceeded the API’s free limit quota.

Once you have an API key, you can send a POST request to the following URL


https://www.googleapis.com/geolocation/v1/geolocate?key=YOUR_API_KEY

You then have the option to include a request body, formatted as JSON. If you include a request body, you have the option to include the following fields:


{
  "homeMobileCountryCode": number,
  "homeMobileNetworkCode": number,
  "radioType": "string",
  "carrier": "string",
  "considerIp": boolean,
  "cellTowers": [],
  "wifiAccessPoints": [ ]
}

If you don’t include a request body, Google will fall back on using the device’s IP address to look up the location.

3 Methods to Determine IP Map Location

There are other methods you can use to view information about an IP address. The best way to get detailed information about things like country, city, state, zip code, and even things like timezone and currency, is to use a dedicated geolocation tool.

Here are a few other ways to determine a user’s IP address or geolocation.

1. Google Overviews and Reports

Google Search Console is a tool from Google that any website owner can use to see how their website performs on Google. It’s useful for learning about the users who access your site and can help you improve your site’s performance in Google searches.

Once you’ve hooked up your website to Google Search Console and verified it, you will get access to performance reports that include information about who accessed your site. The reports include things like device IDs, the country a request was sent from, the query that the user typed into Google that lead them to your site, and much more.

While Google Search Console won’t show you specific users’ IP addresses or exact locations, you can use it to figure out what countries your users are from using filters to narrow down information in the report.

  1. Open the “Search Performance Report”
  2. Navigate to the “Countries” tab
  3. Make sure that “Total clicks,” “Total impressions,” “Average CTR,” and “Average Position” are checked

From here, you should be able to view which countries your users are from and compare your site’s performance across countries.

Use a similar method to find out information about your users’ devices

  1. Open the “Search Performance Report”
  2. Navigate to the “Devices” tab
  3. Make sure that “Total clicks,” “Total impressions,” “Average CTR,” and “Average Position” are checked

Now you can see information like device ID, and compare how your site performs across desktop, tablet, and mobile devices.

2. Logs View

If you have access to your site’s logs, you can get a user’s IP from the access log. This won’t give you information about the IP’s geolocation, however, once you have the IP address, you can use a dedicated geolocation tool to get more detailed information about it.

If you want to find an IP address in your site’s internal logs, and you don’t know the IP you are looking for, you will need to write a regular expression that matches any IP. Then, you’ll use the grep command to look through the logs for any lines that contain strings that match the provided RegEx.

First, let’s look at the regular expression


"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"

An IP address is made up of four sets of numbers, separated by periods. The sets of numbers can contain up to three numbers. In the RegEx above, a set of characters is denoted by the square brackets, and the number of matches is denoted by the curly braces


[0-9]{1,3}

This tells the program to look for a set of 1-3 numeric characters. To create a complete IP, we repeat this pattern three times, separated by periods. We use the backslash \. in front of the period to tell the program to match a literal period character since the period on its own is a special character in RegEx that means “match anything.”

What about the ^ at the beginning of the RegEx? This tells the program to match only the beginning of a line.  In an HTTP access log, every request line starts with the IP that the request came from. Since we only want to look at requests, we use the RegEx beginning line symbol to tell the program to only look at lines that start with IP.

To send this request, we’ll use the grep command through the command line


$ grep "^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}" access.log|more

Here, we are telling grep to look for strings that match the provided pattern inside our access.log. We’re piping the output through more because otherwise, grep would only return the first instance of this match.

We can further refine this query by adding the -o option and piping the output through uniq


$ grep -o "^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}" access.log|uniq|more

This tells grep that we want -only the part of the string that exactly matches our RegEx (i.e., the IP address, not all of the other request information), and filters out requests from duplicate IPs via uniq. Now, we’ll have a list of all the IP addresses that have requested our site.

3. Whois Information Dialog Box

WHOIS is a database that is maintained by ICANN (The International Corporation for Assigned Names and Numbers.) ICANN is a non-profit organization that was established way back at the very beginning of the internet to regulate and maintain security on the internet.

Any time a new domain is registered, the person registering it is required to submit WHOIS information to ICANN. This information includes their name, address, phone number, and email address. ICANN stores this information in a free, publicly available database, so that anyone on the internet can find out who runs which websites.

To look up the information of a website owner on WHOIS, simply enter the website address into a WHOIS search bar. You can also run the query from the command line


$ whois google.com

This query returns a huge amount of information, including the registrar’s name and address, the address of the servers that sent the response, the date the site was created, when it was last updated, and more. 

WHOIS can also be used to return information about an IP address


$ whois 187.204.XXX.XX

The last numbers of the writer’s IP have been obscured here for privacy, but running a similar query on any IP will return information such as the country, phone number, and address of the location that the request was sent from.

Wrapping Up IP Locator In Google Maps

Knowing a user’s physical location is incredibly useful. It can help you serve tailored content such as rendering pages in the appropriate language for the user's location or displaying the correct currency for a user. It can also be used to provide location services or verify that a user’s request is not fraudulent, and more.

Use AbstractAPI’s IP Geolocation API to get accurate and detailed information about any IP—from the user’s country, city, and zip code, to whether they are using a VPN (Virtual Private Network), their connection type, currency, and more. 

Google Maps IP Geolocation FAQs

How Do I Find The Exact Location Of An Ip Address?

There are several ways to find the exact location of an IP. One method is to use the WHOIS protocol, either via an online search bar or through the command line. Another method is to use a dedicated geolocation API, such as AbstractAPI’s IP Geolocation API.

Can You Determine Location From Ip Address?

Yes. Using a geolocation API or similar method, you can determine an IP’s general geolocation. This will not give you information such as an exact street address, name of the device’s owner, phone number, or any other identifying information.

What it will give you is an approximate location based on latitude and longitude, as well as country, city, and sometimes zipcode information.

How Accurate is IP-Based Geolocation?

IP-based geolocation is fairly accurate. It can get between 55 percent to 80 percent accuracy for a user's region or state. For a city, the accuracy is usually between 50 and 75 percent. The actual accuracy varies depending on the provider and the location of the device.

5/5 stars (5 votes)

Elizabeth (Lizzie) Shipton
Lizzie Shipton is an adept Full Stack Developer, skilled in JavaScript, React, Node.js, and GraphQL, with a talent for creating scalable, seamless web applications. Her expertise spans both frontend and backend development, ensuring innovative and efficient solutions.
Get your free
IP Geolocation API
API
key now
Get the location of any IP with an up-to-date API serving data for city, region, and country.
get started for free

Related Articles

Get your free
API
IP Geolocation API
key now
4.8 from 1,863 votes
See why the best developers build on Abstract
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required