mapbox / mapbox/MapboxGeocoder.swift

Migrate response parsing to Turf

Aperta
#216 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Swift
Stelle
133
Fork
46
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

This library should add the Swift port of Turf as a dependency. GeocodeResult and much of the Placemark struct’s Codable conformance should be replaced by FeatureCollection.

Rationale

This library has a significant amount of response parsing code. Even parsing something as simple as a set of routable points is a hassle:

https://github.com/mapbox/MapboxGeocoder.swift/blob/9dcd38e8bfb2933912f35cd9ecb6ae6ed97565d6/Sources/MapboxGeocoder/MBPlacemark.swift#L453-L460

The existing code is functional, but it requires manual updates any time the Geocoding API changes. Supporting a companion API such as the Japan Search API requires extra care just to get something functional.

As it happens, both APIs’ response formats are valid GeoJSON by design. The Swift port of Turf contains full-fledged, well-tested GeoJSON parsing functionality and model types. MapboxDirections successfully migrated to Turf for its geometry-related needs in mapbox/mapbox-directions-swift#382.

This library would continue to be a lightweight, maintainable wrapper atop the search APIs for use cases that don’t require the full heft of the search SDK or that require specialty endpoints like batch geocoding. Conversions to other standard iOS libraries like Contacts would remain, but the smaller codebase would make it easier to support additional Swift platforms like Linux and Windows with negligible overhead.

Implementation notes

Much of the metadata for each result is stored in GeoJSON foreign members, which are now supported by Turf: mapbox/turf-swift#175.

Turf doesn’t bridge backwards to Objective-C. In order for this library to retain Objective-C support, it would need to wrap any Turf types in Objective-C-compatible classes. That might not be much of a problem in the short term, since the response parsing is mostly an implementation detail. However, to achieve the long-term maintainability gains described above, we may want to limit Objective-C support to the current functionality or even drop it in future versions.

/ref mapbox/MapboxStatic.swift#112
/cc @OttyLab @tsuz

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da Sources/MapboxGeocoder/MBPlacemark.swift, in particolare dall’analisi della risposta intorno alle righe collegate, e controlla il riferimento a MapboxStatic.swift alla riga 112. Confronta la gestione esistente di Codable in GeocodeResult e Placemark con il supporto di Turf per FeatureCollection, quindi verifica che le risposte di ricerca previste e l’ambito di compatibilità Objective-C dichiarato siano coperti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
swift
Ambito
api
Tipo di issue
Refactoring
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.