2

I'm working on a iOS project with Swift on Xcode, and i need to show a map with some routes drawn on it. I created the map view using Google Maps SDK for iOS and it works well. I use KML.swift to parse the KML file.

The problem is that i want to load the routes for the map from a KML and i don't see how to do it. On Android, the SDK allows you to add a layer from a KML and add that layer to the map easy (more or less), but i can't find the way to do something like that on the iOS SDK.

Is there any way to do it?

Thanks in advance.

3

1 Answer 1

0

You can now do so with GoogleMapsUtils. The KML file can be parsed using GMUKMLParser and rendered with GMSMapView.

Create instances of GMSMapView and GMUKMLParser

let mapView: GMSMapView!
let kmlParser: GMUKMLParser!

func renderKml() {
    guard let path = Bundle.main.path(forResource: "uae_map", ofType: "kml") else {
        print("Invalid path")
        return
    }
    
    let url = URL(fileURLWithPath: path)
    
    kmlParser = GMUKMLParser(url: url)
    kmlParser.parse()
    
    let renderer = GMUGeometryRenderer(
        map: mapView,
        geometries: kmlParser.placemarks,
        styles: kmlParser.styles,
        styleMaps: kmlParser.styleMaps
    )
    
    renderer.render()
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.