(ctx context.Context, lat, lng float64, language string)
| 88 | } |
| 89 | |
| 90 | func (e *geocodingExtractor) getGeocoding(ctx context.Context, lat, lng float64, language string) ([]driver.MediaMeta, error) { |
| 91 | values := url.Values{} |
| 92 | values.Add("longitude", fmt.Sprintf("%f", lng)) |
| 93 | values.Add("latitude", fmt.Sprintf("%f", lat)) |
| 94 | values.Add("limit", "1") |
| 95 | values.Add("access_token", e.settings.MediaMetaGeocodingMapboxAK(ctx)) |
| 96 | if language != "" { |
| 97 | values.Add("language", language) |
| 98 | } |
| 99 | |
| 100 | resp, err := e.client.Request( |
| 101 | "GET", |
| 102 | mapBoxURL+"?"+values.Encode(), |
| 103 | nil, |
| 104 | request.WithContext(ctx), |
| 105 | request.WithLogger(e.l), |
| 106 | ).CheckHTTPResponse(http.StatusOK).GetResponse() |
| 107 | if err != nil { |
| 108 | return nil, fmt.Errorf("failed to get geocoding from mapbox: %w", err) |
| 109 | } |
| 110 | |
| 111 | var geocoding MapboxGeocodingResponse |
| 112 | if err := json.Unmarshal([]byte(resp), &geocoding); err != nil { |
| 113 | return nil, fmt.Errorf("failed to unmarshal geocoding from mapbox: %w", err) |
| 114 | } |
| 115 | |
| 116 | if len(geocoding.Features) == 0 { |
| 117 | return nil, nil |
| 118 | } |
| 119 | |
| 120 | metas := make([]driver.MediaMeta, 0) |
| 121 | contexts := geocoding.Features[0].Properties.Context |
| 122 | if contexts.Street != nil { |
| 123 | metas = append(metas, driver.MediaMeta{ |
| 124 | Key: Street, |
| 125 | Value: contexts.Street.Name, |
| 126 | }) |
| 127 | } |
| 128 | if contexts.Locality != nil { |
| 129 | metas = append(metas, driver.MediaMeta{ |
| 130 | Key: Locality, |
| 131 | Value: contexts.Locality.Name, |
| 132 | }) |
| 133 | } |
| 134 | if contexts.Place != nil { |
| 135 | metas = append(metas, driver.MediaMeta{ |
| 136 | Key: Place, |
| 137 | Value: contexts.Place.Name, |
| 138 | }) |
| 139 | } |
| 140 | if contexts.District != nil { |
| 141 | metas = append(metas, driver.MediaMeta{ |
| 142 | Key: District, |
| 143 | Value: contexts.District.Name, |
| 144 | }) |
| 145 | } |
| 146 | if contexts.Region != nil { |
| 147 | metas = append(metas, driver.MediaMeta{ |
no test coverage detected