Back to all examples

EV chargers nearby

This example on GitHub

Fast charging stations near one location, filtered by connector and power, with each station's connectors on click

EV chargers nearby
import { TomTomConfig } from '@tomtom-org/maps-sdk/core';
import { PlacesModule, TomTomMap } from '@tomtom-org/maps-sdk/map';
import { discoverPlaces } from '@tomtom-org/maps-sdk/services';
import './style.css';
import { API_KEY } from './config';

// (Set your own API key when working in your own environment)
TomTomConfig.instance.put({ apiKey: API_KEY, language: 'en-GB' });

const utrechtCentre: [number, number] = [5.1214, 52.0907];

(async () => {
    const map = new TomTomMap({
        mapLibre: {
            container: 'sdk-map',
            center: utrechtCentre,
            zoom: 12,
        },
    });

    const chargingStations = await discoverPlaces({
        filters: { poiCategories: ['CHARGING_LOCATION'], connectors: ['IEC62196Type2CCS'], minPowerKW: 50 },
        geoBias: { position: utrechtCentre, radiusMeters: 5000 },
        limit: 50,
    });

    const placesModule = await PlacesModule.create(map);
    await placesModule.show(chargingStations);

    const stationName = document.querySelector('#station-name') as HTMLParagraphElement;
    const stationAddress = document.querySelector('#station-address') as HTMLSpanElement;
    const connectorList = document.querySelector('#connector-list') as HTMLDListElement;

    placesModule.events.places.on('click', (station) => {
        const { poi, address, chargingPark } = station.properties;
        stationName.textContent = poi?.name ?? address.freeformAddress;
        stationAddress.textContent = address.freeformAddress;

        const rows = (chargingPark?.connectors ?? []).map(({ connector, count }) => {
            const type = document.createElement('dt');
            type.textContent = connector.type;
            const power = document.createElement('dd');
            power.textContent = `${count} × ${connector.ratedPowerKW} kW ${connector.currentType}`;
            const row = document.createElement('div');
            row.append(type, power);
            return row;
        });
        connectorList.replaceChildren(...rows);
    });
})();

Fast CCS chargers around Utrecht appear as pins, and a click on one lists its connectors and their power.

  • connectors and minPowerKW in filters drop every station that fails them, so PlacesModule.show draws the response unchanged.
  • events.places hands the click handler the clicked Place, typed, rather than a raw map feature.
  • Its chargingPark.connectors already groups the connectors by type and power, with a count each, so the panel prints one line per group.

Related examples