Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mapbox Cookbook

You're reading from  Mapbox Cookbook

Product type Book
Published in Mar 2016
Publisher
ISBN-13 9781784397357
Pages 264 pages
Edition 1st Edition
Languages

Table of Contents (13) Chapters

Loading GeoJSON and drawing a polyline


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.

How to do it…

Perform the following steps:

  1. 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 a route.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.

  2. 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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}