Recently, I worked on a project that required integrating Google Maps to help users find the five closest specific activities near their postcode or address. The goal was to display these activities along with their distances and provide the best route to reach them. This experience highlighted the power and versatility of Google Maps APIs and underscored the importance of cost optimisation. In this article, I will share insights into the different Google Maps APIs, their use cases, associated costs, and strategies to minimize expenses by carefully selecting APIs and alternative solutions.
Overview of Google Maps APIs
The Google Maps Platform is organized into three core categories:
- Maps: Visualize geospatial data.
- Routes: Provide directions and calculate distances.
- Places: Access detailed information about locations.
Each category comprises specific APIs tailored to different functionalities. In the context of my project, I utilized a combination of these APIs to deliver an effective and cost-efficient solution.
Maps APIs
1. Dynamic Maps
Dynamic Maps APIs provide interactive maps that users can interact with, including zooming, panning, and clicking on elements like markers and overlays. These maps are highly customizable, enabling developers to create detailed, real-time map views.
- Use Case: Embedding fully interactive maps into web or mobile apps where users can explore data points, navigate, or get directions.
2. Maps Embed API
The Maps Embed API is a simple, customizable, and free API that allows developers to embed a Google Map with default or defined settings, such as a place marker or a street view.
- Use Case: Adding an interactive Google Map to a webpage with predefined functionality without complex code.
3. Maps SDK for Android & iOS
The Maps SDKs for Android and iOS provide native APIs that allow developers to embed interactive maps into mobile apps, along with features like user location tracking, route drawing, and other geospatial visualizations.
- Use Case: Native mobile applications needing interactive maps, directions, or place markers.
4. Dynamic Street View
Dynamic Street View APIs allow users to access panoramic, 360-degree imagery. The Street View experience can be embedded directly into apps and websites, enabling users to explore real-world locations virtually.
- Use Case: Adding an interactive, real-world virtual exploration experience to apps or websites.
5. Map Tiles
Map tiles are the fundamental building blocks of map imagery. The Map Tiles API allows developers to request standard map tiles (2D or 3D), including highly detailed, photorealistic 3D tiles.
- Use Case: Customizing or overlaying data on Google’s tiled maps for 2D or 3D environments, often used for geospatial applications requiring detailed views.
6. Aerial View API
The Aerial View API offers high-resolution, bird’s-eye view imagery that provides a unique aerial perspective of locations.
- Use Case: Incorporating high-quality aerial views in apps that require visualizing locations from an overhead perspective.
7. Static Maps
Static Maps API provides non-interactive map images that can be embedded into websites or apps. They are ideal for instances where simple map displays are needed without user interaction.
- Use Case: Embedding non-interactive maps on pages, such as for visualizing locations or routes in a simplified format.
8. Static Street View
The Static Street View API allows you to embed non-interactive, static images of Street View panoramas. It offers a snapshot of a location without the need for interactivity.
- Use Case: Embedding a simple, fixed street view image of a particular location.
Google Maps API Pricing Breakdown
Product | Usage | Monthly Cost |
---|---|---|
Dynamic Maps | ||
Maps Embed API | Unlimited | $0 |
Maps SDK for Android | 1,000 requests | $7 |
Maps SDK for iOS | 1,000 requests | $7 |
Maps JavaScript API | 1,000 requests | $7 |
Dynamic Street View | ||
Maps SDK for Android | 1,000 requests | $14 |
Maps SDK for iOS | 1,000 requests | $14 |
Maps JavaScript API | 1,000 requests | $14 |
Map Tiles | ||
Photorealistic 3D Tiles | 1,000 root tile requests | $6 |
2D Tiles | 1,000 requests | $0.60 |
Street View Tiles | 1,000 requests | $2 |
Aerial View | ||
Aerial View API | 1,000 requests | $16 |
Static Maps | ||
Maps Static API | 1,000 requests | $2 |
Static Street View | ||
Street View API | 1,000 requests | $7 |
Routes APIs
The Routes API provides various routing and road-related functionalities. This API allows developers to compute optimal routes, snap to roads, and perform route optimizations for logistics and transportation use cases.
1. Navigation SDK
The Navigation SDK provides navigation services for mobile and web applications, allowing users to receive real-time directions, updates, and rerouting based on live traffic data.
- Use Case: Real-time navigation for mobile or web applications, commonly used in delivery, transportation, or any app requiring live guidance.
2. Roads API
The Roads API enables applications to map GPS coordinates to the most accurate road segments, or to snap the user’s current location to a road or nearest possible road.
- Use Case: Tracking the precise path that a vehicle travels, ensuring accurate mapping of routes.
3. Routes: Compute Routes
This API computes directions between locations and supports a variety of transportation modes, including walking, driving, cycling, and public transit. It offers various service levels, such as Basic, Advanced, and Preferred, with increasing levels of detail and precision.
- Use Case: Applications that require optimal route computation and accurate driving or walking directions.
4. Routes: Compute Routes Matrix
Similar to the basic route calculation but allows the computation of distance and time between multiple origin-destination pairs, forming a matrix of routes.
- Use Case: Delivery or rideshare apps that need to calculate multiple distances and times between various locations.
5. Route Optimization
This API is designed to optimize vehicle routing for large fleets, helping to assign tasks and calculate optimal routes efficiently. It includes Fleet Routing for large operations and Single Vehicle Routing for simpler logistics tasks.
- Use Case: Fleet management systems, delivery applications, and logistics platforms requiring optimal task and route assignment.
Routes API Pricing Breakdown
Product | Usage | Monthly Cost |
---|---|---|
Navigation | ||
Navigation SDK | 1,000 destinations | $0 |
Roads API | ||
Snap to Roads | 1,000 requests | $10 |
Nearest Roads | 1,000 requests | $10 |
Routes: Compute Routes | ||
Basic | 1,000 requests | $5 |
Advanced | 1,000 requests | $10 |
Preferred | 1,000 requests | $15 |
Routes: Compute Routes Matrix | ||
Basic | 1,000 elements | $5 |
Advanced | 1,000 elements | $10 |
Preferred | 1,000 elements | $15 |
Route Optimization | ||
Fleet Routing | 1,000 shipments x optimization | $30 |
Single Vehicle Routing | 1,000 shipments x optimization | $10 |
Places APIs
The Places API provides a range of functionalities for retrieving information about locations such as addresses, place details, photos, and geographical coordinates. These APIs are used extensively in applications requiring geospatial data, address validation, and nearby searches.
1. Address Validation
The Address Validation API checks if a given address is valid by cross-referencing it with known geographic databases.
- Use Case: Applications that require reliable and accurate address input from users, such as in shipping, deliveries, or registrations.
2. Autocomplete
The Autocomplete API suggests potential addresses or places as the user types. It streamlines input, reducing errors by presenting real-time suggestions based on user input.
- Use Case: Enhancing user experience by reducing typing errors and improving address search speed in forms or location searches.
3. Geocoding API
The Geocoding API converts physical addresses into geographic coordinates (latitude and longitude) and vice versa, enabling address-based location tracking.
- Use Case: Any service that needs to translate user-input addresses into geographic points on a map, like delivery or navigation applications.
4. Geolocation API
The Geolocation API provides the geographic location of a device using Wi-Fi and cell tower signals instead of GPS.
- Use Case: Locating users who don’t have GPS-enabled devices or for fallback in case of weak GPS signals.
5. Nearby Search
Nearby Search APIs allow developers to search for places in proximity to a specified location. The service level (Basic, Advanced, Preferred) determines the depth and precision of search results.
- Use Case: Apps like restaurant finders, hotel locators, or any service needing nearby points of interest (POI) searches.
6. Place Details
The Place Details API retrieves detailed information about a specific place, including names, addresses, phone numbers, and ratings.
- Use Case: Providing detailed POI information in location-based services like travel guides or restaurant review apps.
7. Place Photos API
The Place Photos API provides access to high-quality photos for a given place, based on user submissions or professional photos tied to a location.
- Use Case: Apps that require visual representations of locations, such as tourism apps, hotel booking platforms, or real estate apps.
8. Text Search
Text Search allows users to search for places using freeform text inputs. The API interprets the user’s query and returns relevant place results, similar to a Google search.
- Use Case: Search functionality in apps needing a flexible query system, where users may search for anything from “Italian restaurants” to “nearest pharmacy.”
9. Time Zone API
The Time Zone API returns the time zone information for a given location, including details such as UTC offset and whether daylight savings time is observed.
- Use Case: Global applications needing accurate time zone data for scheduling, travel planning, or user localization.
Places API Pricing Breakdown
Product | Usage | Monthly Cost |
---|---|---|
Address Validation | ||
Address Validation | 1,000 requests | $17 |
Autocomplete | ||
Autocomplete Requests | 1,000 requests | $2.83 |
Autocomplete with Address Validation Preferred | 1,000 sessions | $25 |
Autocomplete with Place Details Preferred | 1,000 sessions | $25 |
Geocoding | ||
Geocoding API | 1,000 requests | $5 |
Geolocation API | 1,000 requests | $5 |
Nearby Search | ||
Basic | 1,000 requests | $32 |
Advanced | 1,000 requests | $35 |
Preferred | 1,000 requests | $40 |
Place Details | ||
Basic | 1,000 requests | $17 |
Advanced | 1,000 requests | $20 |
Preferred | 1,000 requests | $25 |
Place Photos | ||
Place Photos API | 1,000 requests | $7 |
Text Search | ||
Basic | 1,000 requests | $32 |
Advanced | 1,000 requests | $35 |
Preferred | 1,000 requests | $40 |
Time Zone API | 1,000 requests | $5 |
Environment APIs
The Environment APIs provide access to real-time environmental data, including air quality, pollen levels, and solar insights. These APIs are valuable for applications focused on health, sustainability, and environmental impact.
1. Air Quality API
The Air Quality API provides real-time data on the air quality of a specific location, including levels of pollutants such as particulate matter (PM2.5, PM10), ozone (O3), and nitrogen dioxide (NO2).
- Use Case: Applications that provide users with local air quality information for health and safety purposes, such as weather apps or environmental monitoring platforms.
2. Pollen API
The Pollen API offers real-time pollen count data, including various types of pollen such as tree, grass, and weed pollen.
- Use Case: Health and wellness apps designed for allergy sufferers, providing real-time updates on pollen levels in a specific area.
3. Building Insights API (Solar)
The Building Insights API provides solar potential information for buildings, allowing users to estimate how much solar energy a building can generate based on factors like sunlight exposure and building structure.
- Use Case: Solar energy companies or sustainability-focused apps that help users assess the feasibility of installing solar panels on their property.
4. Data Layers API
The Data Layers API allows developers to overlay specialized environmental data layers, such as weather, pollution, or other real-time datasets, on top of existing maps.
- Use Case: Advanced mapping applications that require real-time environmental data, such as disaster management tools, weather monitoring systems, or agricultural platforms.
Environment API Pricing Breakdown
Product | Usage | Monthly Cost |
---|---|---|
Air Quality API | 1,000 requests | $5 |
Pollen API | 1,000 requests | $10 |
Building Insights API (Solar) | 1,000 requests | $10 |
Data Layers API | 1,000 requests | $75 |
Early API Choices for my Finder component: Location and Route Calculation
In my original approach to the project, I selected the following Google Maps APIs:
Maps APIs
- Dynamic Maps: Used to display interactive maps where users could visualize the locations of the nearest activities. This API allowed for full customization, enabling users to interact with the map, zoom in and out, and see markers for various partner activities stored in a JSON file (activity name / activity address etc.).
Distance APIs
For calculating the distances and determining the best routes to the nearest activities, I utilized two key APIs:
- Directions API: Provided optimal routes for driving, ensuring users received accurate travel directions.
- Distance Matrix API: Used to compute travel distances and times between multiple locations, which allowed users to compare routes and select the best option based on real-time traffic data.
Geocoding API
In my application, the Geocoding API was used to convert user-inputted postcodes or addresses into geographic coordinates (latitude and longitude). This was essential for pinpointing the user’s location on the map.
Smooth Launch, Unexpected API Costs: What Went Wrong?
Everything was working fine and the Finder component went live. However, after a few weeks, I recognized a significant and unsustainable increase in API costs on the Google Console, which required immediate attention to manage.
Here’s a list of the vulnerable issues:
- Matrix API Costs: The use of the Distance Matrix API was significantly enhancing the overall cost.
- On-the-Fly Activity Calculations: Coordinates for over 1,000 activities across three different continents were being calculated dynamically, further contributing to the API cost.
This situation required an immediate and urgent review of the entire logic behind the Finder component. The rising API costs, particularly driven by the frequent use of the Distance Matrix API and the dynamic, on-the-fly calculation of activity coordinates for a large dataset, made the initial approach unsustainable. The sheer volume of activities spread across three continents, combined with the inefficiency in handling these calculations, demanded a thorough re-evaluation. It was clear that optimizing the use of APIs and restructuring the logic would be essential to ensure the long-term viability and cost-effectiveness of the project.
A Smarter Approach: Reducing API Costs
The key steps to resolving the cost issue were twofold:
- Improving the JSON File: By adding pre-calculated geographic coordinates in the JSON file for all activities using the Geocoding API just once, I eliminated the need to regenerate these coordinates during every user search. This significantly reduced API usage and improved efficiency.
- Switching to Mathematical Distance Calculation: To further cut costs, I replaced the Google Maps API distance calculations with a faster and more efficient mathematical approach using the the straight-line distance between two points on the Earth’s surface (Haversine) formula. Although this method is less accurate, it allowed for substantial cost savings without compromising too much on performance.
Setting Up Daily API Cost Limits
In addition to optimizing the Finder component, we implemented a daily cost limit for the required APIs. This ensured that we had better control over API usage, preventing any unexpected spikes in cost. By configuring the Google Cloud Console to cap daily spending on the APIs, we could manage and predict expenses more effectively, ensuring the project stayed within budget while still delivering the necessary functionality. This safeguard allowed us to maintain sustainable API usage without compromising performance.
From High Costs to Savings: A massive Reduction in API Expenditures
By implementing these new approaches—pre-calculating coordinates, switching to the as-the-crow-flies distance formula, and setting up daily cost limits—we achieved an immediate and dramatic reduction in API expenses. The monthly cost dropped by 94.95%, bringing the project well below the budget we had initially planned. This strategic optimization ensured that the Finder component remained both cost-effective and high-performing, meeting all project objectives without exceeding financial constraints.
Final Thoughts
When integrating Google Maps APIs into your application (a principle that applies to all non-free services), it’s crucial to balance delivering functionality with managing costs. Strategic planning around which APIs to use and optimizing their usage can help ensure your app is both powerful and cost-effective.
By reducing unnecessary API calls, using efficient alternatives for certain functions, and closely monitoring costs, you can create an application that meets user needs while staying within budget. Regularly reviewing and refining your approach ensures that your project remains sustainable as it scales.