From 0650345fede8e2eed60bdfa5bf706dcba111141d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=A4ckevik?= Date: Wed, 1 Jul 2026 17:30:15 +0200 Subject: [PATCH] feat(geocoding): opt-in Permanent tier support Add Permanent bool to ReverseGeocodeRequest and BatchReverseGeocodeRequest. When true, passes permanent=true to the Mapbox API, selecting the Permanent tier which permits storing and caching geocoding results. Defaults to false (Temporary tier) to preserve backward compatibility. --- geocoding_batch_reverse.go | 5 +++++ geocoding_reverse.go | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/geocoding_batch_reverse.go b/geocoding_batch_reverse.go index 78c5d7e..ab4d904 100644 --- a/geocoding_batch_reverse.go +++ b/geocoding_batch_reverse.go @@ -13,6 +13,9 @@ import ( type BatchReverseGeocodeRequest struct { // Queries are the coordinates to reverse geocode. Must contain 1–1000 items. Queries []ReverseGeocodeQuery + // Permanent requests Permanent tier geocoding, which permits storing results. + // Defaults to Temporary tier when false. + Permanent bool } // ReverseGeocodeQuery is a single query in a batch reverse geocode request. @@ -28,6 +31,7 @@ type batchGeocodeQuery struct { Types string `json:"types"` Longitude float64 `json:"longitude"` Latitude float64 `json:"latitude"` + Permanent bool `json:"permanent"` } // BatchReverseGeocode performs a batch reverse geocode lookup using Geocoding v6 Batch. @@ -53,6 +57,7 @@ func (c *Client) BatchReverseGeocode(ctx context.Context, req *BatchReverseGeoco Types: "address", Longitude: q.Longitude, Latitude: q.Latitude, + Permanent: req.Permanent, } } diff --git a/geocoding_reverse.go b/geocoding_reverse.go index 6ed5918..e378ac2 100644 --- a/geocoding_reverse.go +++ b/geocoding_reverse.go @@ -16,6 +16,9 @@ type ReverseGeocodeRequest struct { Longitude float64 // Latitude is the coordinate to reverse geocode. Latitude float64 + // Permanent requests Permanent tier geocoding, which permits storing results. + // Defaults to Temporary tier when false. + Permanent bool } // ReverseGeocode performs a single reverse geocode lookup using Geocoding v6. @@ -29,6 +32,9 @@ func (c *Client) ReverseGeocode(ctx context.Context, req *ReverseGeocodeRequest) params := url.Values{} params.Set("longitude", strconv.FormatFloat(req.Longitude, 'f', -1, 64)) params.Set("latitude", strconv.FormatFloat(req.Latitude, 'f', -1, 64)) + if req.Permanent { + params.Set("permanent", "true") + } endpoint := c.baseURL + "/search/geocode/v6/reverse?" + params.Encode() httpReq, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)