Back to blog
Guides & How-tos2026-03-15·10 min read

Extract Google Maps Data with JavaScript API: Full Guide

By Ibrahim DemolCEO IBLeadUpdated June 12, 2026

Google Maps holds one of the largest public databases of business information on the planet. Every search returns a list of companies with addresses, phone numbers, websites, ratings, and reviews. If you want to extract Google Maps data with JavaScript API at scale, this guide walks you through the exact steps — from setting up your API key to running three working examples.

By the end, you'll know how to geocode addresses, search businesses by category and location, and calculate directions. You'll also understand where the API falls short and what to do about it.


Why Extract Data from Google Maps?

The most common reason is lead generation. Sales teams pull lists of local businesses — restaurants, dentists, contractors — filtered by city or category. But that's not the only use case.

Marketers use Google Maps data to monitor competitors: pricing signals, facility details, menu items. Real estate analysts map business density to evaluate neighborhoods. Franchise operators identify gaps in their catchment area.

In all these cases, the goal is the same: turn a Google Maps search into a structured, exportable dataset.


Setting Up Your Google Maps API Key

Before writing a single line of code, you need an API key. Here's how to get one.

Go to console.cloud.google.com. Create a new project — give it any name. Once the project is created, select it from the top navigation.

Next, go to APIs & Services → Library. Every API you plan to use must be enabled individually. For the examples in this guide, you'll need:

  • Geocoding API — converts addresses to coordinates
  • Places API (New) — searches businesses by category and location
  • Directions API — calculates routes between two points

Enable each one by clicking on it and hitting "Enable."

After enabling your first API, go to APIs & Services → Credentials. Your API key appears there. Copy it and store it somewhere safe.

One important note: the Google Maps API is a paid service. You'll need to attach a billing account to your project. Google provides $200 in free monthly credits, which covers roughly 40,000 Geocoding requests or 6,250 Places API requests before charges kick in.


Example 1: Geocoding an Address

Geocoding converts a human-readable address into latitude and longitude coordinates. This is the foundation of most location-based workflows.

What the Geocoding API Does

Send an address string → get back coordinates. That's it. The response also includes the Place ID, which you can reuse in other API calls.

The Request URL

The base URL looks like this:

https://maps.googleapis.com/maps/api/geocode/json?address=YOUR_ADDRESS&key=YOUR_API_KEY

The address parameter must be URL-encoded. Spaces become %20, commas become %2C, and so on.

JavaScript Implementation

const address = encodeURIComponent("1600 Amphitheatre Parkway, Mountain View, CA");
const apiKey = "YOUR_API_KEY";

const url = `https://maps.googleapis.com/maps/api/geocode/json?address=${address}&key=${apiKey}`;

fetch(url)
  .then(response => response.json())
  .then(data => {
    const location = data.results[0].geometry.location;
    console.log("Latitude:", location.lat);
    console.log("Longitude:", location.lng);
    console.log("Place ID:", data.results[0].place_id);
  })
  .catch(error => console.error("Error:", error));

Reading the Response

The response is a JSON object. The coordinates sit at results[0].geometry.location. You get lat and lng as separate fields. The Place ID is at results[0].place_id — save it if you plan to use the Places or Directions API next.

Geocoding API cost: approximately $5 per 1,000 requests. The $200 monthly credit covers 40,000 requests before billing starts.


Example 2: Searching for Businesses by Category

This is where things get useful for lead generation. The Places API (New) lets you search for businesses by type and location. You define a category, a geographic area, and a result count — the API returns matching businesses.

Enabling the Right API

Make sure you've enabled the Places API (New) in your Google Cloud console, not the legacy Places API. The new version uses a different endpoint and request format.

Setting Up the Request

The Places API (New) uses a POST request to:

https://places.googleapis.com/v1/places:searchNearby

You send a JSON body with your search parameters and include your API key and field mask in the headers.

JavaScript Implementation

const apiKey = "YOUR_API_KEY";

const payload = {
  includedTypes: ["restaurant"],
  maxResultCount: 10,
  locationRestriction: {
    circle: {
      center: {
        latitude: 40.7128,
        longitude: -74.0060
      },
      radius: 500.0
    }
  }
};

const headers = {
  "Content-Type": "application/json",
  "X-Goog-Api-Key": apiKey,
  "X-Goog-FieldMask": "places.displayName,places.formattedAddress,places.nationalPhoneNumber,places.websiteUri,places.rating"
};

fetch("https://places.googleapis.com/v1/places:searchNearby", {
  method: "POST",
  headers: headers,
  body: JSON.stringify(payload)
})
  .then(response => response.json())
  .then(data => {
    data.places.forEach(place => {
      console.log(place.displayName.text, "-", place.formattedAddress);
    });
  })
  .catch(error => console.error("Error:", error));

Understanding Field Masks

The X-Goog-FieldMask header controls which data fields the API returns. Only request what you need — this affects both performance and cost.

Common field masks for business data extraction:

Field What it returns
places.displayName Business name
places.formattedAddress Full address
places.nationalPhoneNumber Phone number
places.websiteUri Website URL
places.rating Average Google rating
places.userRatingCount Number of reviews
places.regularOpeningHours Opening hours

The 120-Result Limit

Here's a hard constraint: the Places API returns a maximum of 20 results per request, and pagination caps at around 60 total results per search area. If you need more, you have to tile your geographic area into smaller circles and run multiple requests.

This is the main reason developers look for alternatives when they need to extract Google Maps data at scale.

Places API cost: approximately $32 per 1,000 requests for basic data fields. Advanced fields (reviews, photos) cost more.


Example 3: Calculating Directions Between Two Points

The Directions API calculates routes between an origin and a destination. It returns travel time, distance, and step-by-step instructions.

Use Cases

Route optimization for field sales teams. Delivery time estimates. Mapping service coverage areas. Identifying which businesses fall within a specific drive time from a location.

The Request URL

https://maps.googleapis.com/maps/api/directions/json?origin=ORIGIN&destination=DESTINATION&mode=driving&departure_time=TIMESTAMP&key=YOUR_API_KEY

For origin and destination, you can use:

  • A formatted address: "Montreal, QC, Canada"
  • Coordinates: "45.5017,-73.5673"
  • A Place ID: "place_id:ChIJDbdkHFQayUwR7-8fITgxTmU"

JavaScript Implementation

const apiKey = "YOUR_API_KEY";
const origin = "place_id:ChIJDbdkHFQayUwR7-8fITgxTmU"; // Montreal
const destination = "place_id:ChIJrxNRX7IFzkwR7RXdMeFRaUU"; // Ottawa
const departureTime = Math.floor(Date.now() / 1000); // Current timestamp

const url = `https://maps.googleapis.com/maps/api/directions/json?origin=${encodeURIComponent(origin)}&destination=${encodeURIComponent(destination)}&mode=driving&departure_time=${departureTime}&key=${apiKey}`;

fetch(url)
  .then(response => response.json())
  .then(data => {
    const route = data.routes[0].legs[0];
    console.log("Distance:", route.distance.text);
    console.log("Duration:", route.duration.text);
    console.log("Duration in traffic:", route.duration_in_traffic?.text);
  })
  .catch(error => console.error("Error:", error));

Converting Dates to Timestamps

The departure_time parameter requires a Unix timestamp — the number of seconds since January 1, 1970. To convert a specific date, use epochconverter.com or run this in JavaScript:

const date = new Date("2025-06-15T09:00:00");
const timestamp = Math.floor(date.getTime() / 1000);
console.log(timestamp);

Directions API cost: approximately $5 per 1,000 requests.


Using the official Google Maps API keeps you within Google's terms of service. That's the safest approach. But there are still rules to follow.

Respect rate limits. Each API has daily quotas. Exceeding them triggers errors and potential account suspension. Monitor your usage in the Google Cloud console.

Only access public data. The API returns publicly visible business information. Don't attempt to access private user data or bypass authentication.

Don't cache data indefinitely. Google's terms restrict how long you can store certain types of data. Check the specific terms for each API you use.

Commercial use is allowed — with conditions. You can use extracted data for lead generation, market research, and business intelligence. You cannot resell raw Google Maps data as a standalone product.

For direct scraping (without the official API), the legal picture is murkier. Google's terms of service prohibit scraping their properties without permission. Courts have issued mixed rulings on this. The safest path is always the official API.


The Limitations of the Google Maps API

The API works well for small to medium extractions. But it has real constraints when you need volume.

Cost scales fast. The Places API charges ~$32 per 1,000 requests. Extracting 50,000 business listings costs roughly $1,600 in API fees alone — before any development time.

The 120-result cap. No single search returns more than 120 results. Covering a full city requires dozens of overlapping geographic tiles, each with its own API call.

No bulk export. The API returns JSON. You write the code to parse it, deduplicate records, and export to CSV. That's real engineering work.

Data gaps. Not every business has a website, phone number, or email. The API returns what Google has — which varies by location and business type.


The No-Code Alternative: IBLead

If you need to extract Google Maps data without writing API code, IBLead is built for that.

IBLead is a pre-indexed database of 50M+ businesses across 37 countries. Everything is already scraped and indexed — updated weekly. You search by city, postal code, region, or entire country. Filter by category, Google rating, review count, or the technologies a business uses on its website. Then export to CSV instantly.

No API setup. No rate limits to manage. No per-request billing.

IBLead detects 160+ web technologies per business listing — CMS platforms, analytics tools, ad pixels, payment processors. That's data the Google Maps API doesn't return at all. You can also access up to 500 Google reviews per listing, including review text, rating, date, and author.

For 10,000 leads, you're looking at $52 — that's $0.004 per contact. The trial gives you 200 credits to test it yourself.

Start free — 200 credits, no card required


Frequently Asked Questions

Using the official Google Maps API is legal and within Google's terms of service. Direct scraping without the API violates Google's terms and carries legal risk. For commercial use, the API or a licensed data provider is the right approach.

What is the result limit when scraping Google Maps?

The Places API returns a maximum of 20 results per request, with pagination capped at around 60 results per search area. Direct scraping tools often hit a ~120 result limit per query. To cover larger areas, you need to split the geography into smaller tiles.

How much does the Google Maps API cost?

Pricing varies by API type. Geocoding costs ~$5 per 1,000 requests. The Places API costs ~$32 per 1,000 requests for basic data. Directions costs ~$5 per 1,000 requests. Google provides $200 in free monthly credits, which covers moderate usage before charges apply.

Can I export Google Maps data to Excel or CSV?

The API returns JSON — you need to write code to convert it to CSV or Excel. Tools like IBLead skip that step entirely: search, filter, and export directly to CSV in under two minutes.

What data fields can I extract from Google Maps?

Through the official API: business name, address, phone number, website, rating, review count, opening hours, coordinates, and Place ID. IBLead adds email addresses (enriched from business websites), social media profiles, technology stack, and up to 500 full Google reviews per listing.


Wrapping Up

Extracting Google Maps data with the JavaScript API is straightforward once you understand the three core APIs: Geocoding for coordinates, Places for business search, and Directions for routing. Each has clear documentation, predictable pricing, and official support from Google.

The tradeoffs are real though. API costs add up at volume. The result caps require geographic tiling. And you still need to write the code to parse, deduplicate, and export your data.

For developers building location-aware applications, the API is the right tool. For sales teams and marketers who need business lists fast, a pre-indexed solution saves hours of engineering work.

Either way, you now have the full picture to make the right call for your use case.

Ready to get started?

Access every Google Maps business, enriched with emails and legal data.

Try IBLead free