0

I'm trying to get geoJSON:

import GeoJSON
import MapKit

let coordArray: [CLLocationCoordinate2D] = [CLLocationCoordinate2D(latitude: 77, longitude: 44), CLLocationCoordinate2D(latitude: 78, longitude: 45), CLLocationCoordinate2D(latitude: 79, longitude: 46)]

let way: GeoJSONLineString = GeoJSONLineString(coordinates: coordArray)

let features: GeoJSONFeatureCollection = GeoJSONFeatureCollection(dictionary: way.dictionaryRepresentation)
let json = try JSONEncoder().encode(features)

But i have error: Instance method 'encode' requires that 'GeoJSONFeatureCollection' conform to 'Encodable'

kadi4
  • 5
  • 2
  • It's probably best to ask the authors of the `GeoJSON` library you are using. Note, there is also some support for GeoJSON in Apple MapKit. – workingdog support Ukraine Aug 16 '22 at 04:24
  • 1
    You need to include the code for GeoJSONFeatureCollection if this is your own type. Remember that for a type to conform to\ Encodable each of its properties needs to conform to Encodable – Joakim Danielson Aug 16 '22 at 05:22

0 Answers0