The Foundation of Your iOS Mapping App

1215
8
10-19-2017 07:45 PM
Labels (1)
Nicholas-Furness
Esri Regular Contributor
0 8 1,215

Each of our Example Apps is designed to provide some inspiration for your own. If you’re interested in building your own custom app because one of our off-the-shelf apps isn’t quite right for you, then the Example Apps are a great place to start.

With the Maps App for iOS, we show how you might build the foundation of your own ArcGIS Runtime mapping app using Swift.

The open source app (which you can download and build from GitHub) highlights fundamental Runtime functionality and showcases some approaches to coding against asynchronous services. It includes a robust internal framework and a modern, decoupled UI.

In later posts, we’ll take a look at the UI/UX and what it took to put the app together, but for now let’s take a look at using the app.

Search & Geocode

To search, simply start typing into the Search Bar at the top of the screen.

As you type, you’ll see suggestions appear, and you can either pick a suggestion or search for the text you’ve typed.

By default, you can search for places or addresses using the ArcGIS  World Geocoder, and the suggestions will prioritize matches close to the center of the map.

Reverse Geocode

If you tap and hold on the map, you’ll see a magnifier. Use this to pick a point on the map and when you’re done, you’ll get the address of that point.

Turn-by-turn Directions

Whether you’ve searched or reverse-geocoded, the results panel includes a “Directions” button. Tap this to calculate directions from your current location to the search result.

 

At the top of the screen you’ll see an overview of the entire route, and at the bottom you can see turn-by-turn directions. Just swipe through them and the map will update to display the current step. If you ever want to go back to the entire route, simply tap the route summary at the top of the screen.

 

Note: Since the routing service consumes ArcGIS  credits, you'll need to log in to get directions. The ArcGIS Runtime includes a Credentials Cache and by default, if you've already logged in, the Runtime is able to intelligently make use of cached credentials to avoid prompting you for a login.

Switch Basemaps

The application also allows you to pick from a set of basemaps. If you are logged in to an ArcGIS  Organization or to an ArcGIS Portal, then the list of basemaps will reflect those configured for your account. If not, then you'll get to pick from the default ArcGIS  basemaps.

Browse your Web Maps

The last bit of functionality the app provides is the ability to browse and open your Web Maps. When logged in to ArcGIS  the Maps App makes use of the Runtime Portal API to query your content and present you with a list of Web Maps. Simply tap one to open it in the app.

What did we learn building this functionality?

There are some interesting points to consider from all this.

Authentication

In the case of getting directions and browsing Web Maps, the user must log in. But how should your app behave when the user isn't logged in?

When not logged in, we decided to allow the user to search and geocode using the ArcGIS  World Geocoding Service (which is free to use, as long as you're not storing the results).

But once the user is logged in, the Maps App uses the Portal API to determine which Geocoding Service and Routing Service to use and, as mentioned above, which basemaps to list. Your ArcGIS  Organization's Administrator can configure these settings, so it's important that your app reads and honors that configuration.

Lastly, consider how a user should be prompted to log in. For the Maps App we opted to make use of the ArcGIS Runtime's integration with OAuth 2.0, which made implementing login really straightforward.

iOS Location Permissions

It's also important for an iOS app to behave properly if the user hasn't enabled Location Services or has explicitly denied the app access to their location. When possible, asking for directions will get directions from the current location, but if that's not available then the app will get directions from the center of the current map view.

8 Comments
About the Author
Product Manager for the ArcGIS Runtime SDKs, focusing on the Runtime SDK for iOS. My background is in computer science, but my professional career has always been GIS, in particular Utilities.