In this recipe, you will learn how to parse a GeoJSON file and draw a polyline on the map using Mapbox GL. This will be a great start if your purpose is to create applications that draw routes on a map.
Perform the following steps:
Open the
Chapter6-Recipe6-Begin
folder and then the.xcworkspace
file. This project contains a basic Mapbox GL map. It uses the emerald style, which is the best-looking style to display directions. The project also contains aroute.geojson
file. Normally, you would fetch the data from a service, but for the purpose of this recipe, we will use a file stored in our bundle.Our first step is to parse the GeoJSON file and get the coordinates contained in the
geometry.coordinates
array under the features. We will do this in a separate method, as follows:- (void)loadGeoJSONFile { dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queue, ^{ NSString...