go-openchargemap is a Golang interface to the OpenChargeMap API.
The base openchargemap.openapi.yml
comes from OpenChargeMaps's Developer Documentation.
You will need an OpenChargeMap API key -- you can get one by Signing Up and then going to My Apps in your Profile. The examples and tools look for OCM_KEY
in your environment, so export OCM_KEY=<your-key>
We have the following examples:
-
chargemeup
shows how to use thego-openchargemap
library -
ocum_fun.ipynb
Jupyter notebook showing how to use thechargemeup
CLI tool to query the OpenChargeMap API within Python notebooks. -
ocum_3d.ipynb
Jupyter notebook is the same thing, but also generates an OSMBuildings WebGL experience, along with wiht instructions to use it in VR. -
examples/chargers_near_addr.py
is a simple Python script that exercises it too
You can include it in your Go programs with:
go get github.com/neomantra/go-openchargemap
See the chargemeup
sample program for an example with how to use the API. The bindings are created with oapi-codegen.
chargemeup
is a command-line tool for querying the OpenChargeMap API. Although you can build it yourself, you can install it with Homebrew:
brew tap neomantra/homebrew-tap
brew install neomantra/homebrew-tap/go-openchargemap
You can run chargemeup
to get a list of charging stations near a bounding box (lat1,lon1),(lat2,lon2)
:
$ chargemeup -b "(40.63010790372053,-74.2775717248681),(40.7356464076158,-74.09370618215354)" | jq length
41
$ chargemeup -a "Carroll Gardens, NY" --radius 1 | jq '.[].AddressInfo.AddressLine1'
"383 Court St"
"365 Bond St"
"363 Bond St"
"214 3rd Street"
"353 4th Ave"
"302 2ND St"
$ chargemeup --lat 40.63010790372053 --lon -74.2775717248681 --radius 5 | jq length
20
The output is the JSON, although there we are using jq
to count the number of POIs returned.
$ chargemeup --help
usage: ./chargemeup <options> [input]
"chargemeup" assists with queries to OpenChargeMap.
Around Newark is:
chargemeup -p "(40.63010790372053,-74.2775717248681),(40.7356464076158,-74.09370618215354)"
chargemup -a "Newark, NJ" -r 10
chargemeup --lat 40.7356464076158 --lon -74.09370618215354 --radius 5
-a, --address string address to query (requires --radius)
-b, --bbox string bounding box for query, "(lat1,lon1),(lat2,lon2)"
-h, --help show help
-k, --key string API key for OpenChargeMap, env var OCM_KEY)
--lat float32 latitude to query (requires --lon and --radius)
--lon float32 longitude to query (requires --lon and --radius)
-r, --radius float32 radial distance to query in kilometers (requires --address)
-s, --server string API Server for OpenChargeMap, env var OCM_SERVER (default "https://api.openchargemap.io/v3")
-v, --verbose verbose output to stderr
Building is performed with task and our Taskfile.yml:
$ task --list-all
task: Available tasks for this project:
* build:
* build-deps:
* clean:
* default:
* oapi-codegen:
* test:
* tidy:
# needed when the upstream spec changes
$ task oapi-codegen
$ task build
task: [tidy] go mod tidy
task: [build] go build -o chargemeup cmd/chargemeup/main.go
Authored with ❤️ and 🔥 by Evan Wies. Copyright (c) 2024 Neomantra BV.
Many thanks to OpenChargeMap and the community behind it! Thanks to oapi-codegen for the heavy lifting.
Released under the MIT License, see LICENSE.txt.