Skip to main content
This guide will show you how to fetch locations and show them on a map, using data from the Geosearch endpoints. Recommended UI flow:
  1. Use radius or rectangle search to render map pins.
  2. Use connector and EVSE fields from the search response for basic filtering.
  3. When the user opens a pin or charger detail page, call Get location by id.
  4. Display prices from the detail response. If price is absent, show “Price temporarily unavailable.”
Most client-side map libraries offer an onRegionChangeComplete event or similar, which is triggered when the user moves the map.
This event should contain data for the current map position like latitude, longitude, longitudeDelta, latitudeDelta.
To get the correct amount of locations and aggregations, you need to know the aggregationPrecision, latitude, longitude and distance. Fortunately all of this can be retrieved or calculated from the map’s Region data. Let’s look at the main function that will handle that. This sample code is written in TypeScript, but the logic will be the same in all programming languages.
The aggregationPrecision plays an important role in what you get from the Geosearch endpoint, it controls how tightly clustered locations should be.
Let’s dive into the details now: how to get a correct aggregationPrecision and how to adjust it to your needs.
The easiest way to manipulate how tightly locations are aggregated is via the K constant, here you can see examples for different values. Different K values generate very different output, so adjust it to your application needs. Example:
The last step is rendering the markers on map, this differs a lot between popular map libraries, but let’s look at an example built with react-native and the react-native-maps library. We will render red pins for locations and blue pins for aggregations.
❗ This is just an example to show how to display locations as on a map, the Drive API is not meant to be called from client apps. Instead, it should be integrated on your backend, as described in this page.