Ride Up for Android

Gareth Paul Jones
Foursquare
Published in
4 min readDec 7, 2016

--

One of the things we have often heard from developers is that they’d like to deeply integrate location intelligence into their own apps without investing heavily into a custom implementation.

In response to this feedback we’ve been working hard to constantly improve our PlacePicker SDK for Android. This is a simple, beautiful and elegant way to bring location intelligence — right inside your app.

To showcase some of this recent work we built RideUp — a sample ride sharing app.

Overview

Developers

For developers looking to add location intelligence to their app, it’s no easy task. The very thought of building a sample ride-sharing app is one of many complex decisions including location, operations, latency, mapping and much much more.

We built this ride-sharing app to showcase the PlacePicker SDK, which makes it faster and easier for developers to implement location intelligence in their app. In this case we spent less time worrying about where our RideUp users were in the world and potentially more time focused on the many other challenges that come with building or adding features to apps.

You can grab the code for this sample on Github.

Users

After opening the app, users can start their quest to get a ride by tapping on pickup location at the top of the screen. We then present the user with a list of possible venues they’re currently at, as well as an option to search a given city if current location is disabled. If a user taps on a given location they’ll be able to request a vehicle from that venue.

Code Walkthrough

In this walkthrough you will learn how to:

  1. Sign-up for a Foursquare API key
  2. Find the nearest venue
  3. Select the best location

If you want to take a look at the live app before continuing you can download it from the App Store.

This tutorial is written for Android and is intended for those who are familiar with Android development. If you’ve never built an Android app before, check out some of the great online resources to get you started.

Get the code

The best way to start is to grab the code from GitHub and open in Android Studio. The project is built using Android Studio and Gradle.

App structure

The app is made up of essentially two classes:

  1. MainActivity.java | Main Activity to request a veh
  2. Constants.java | A class to contain API keys

Setting up Foursquare API

To sign-up for a free Foursquare API key navigate to developer.foursquare.com and create a new app. After you create a new app you’ll get two very important pieces of information, a client id and client secret. You’ll need both of these to start using the PlacePicker SDK.

In addition you will need a mapbox access token via Mapbox, to power the mapping in our app.

Once you get your client id and client secret, paste them into the FOURSQUARE_CLIENT_KEY and FOURSQUARE_CLIENT_SECRET variables in the public class Constants.

public static final String FOURSQUARE_CLIENT_KEY = "";
public static final String FOURSQUARE_CLIENT_SECRET = "";
public static final String MAPBOX_ACCESS_TOKEN = "";

Note: For production applications, we’d recommend the Android KeyStore API for storing these values.

Build and run the app

At this point you should be able to build and run the app. Tap on the Map to see some random vehicles. Tap on the location bar and you should be able to see the venue you’re currently at or the venue you want to request a pick-up from.

Now that you’ve got your app up and running, lets look into some of the code.

Quick and Easy Implementation

Android Developers can quickly add the PlacePicker SDK to their app in a few minutes by simply adding the SDK to their build.gradle file.

compile 'com.foursquare:placepicker:0.6.1'

Determine the current location

The MainActivity class is where we call the methods to work with the PlacePicker SDK.

PlacePickerSdk.get().getCurrentPlace(new PlacePickerSdk.CurrentPlaceResult() {
@Override
public void success(Venue venue, boolean confident) {
lat = venue.getLocation().getLat();
lng = venue.getLocation().getLng();
}

Special thanks to Kyle, Ryan, Matthew and the team at Mapbox. We work in a creative environment where we love to jam on ideas with engineers, product managers and designers. Our mission is to provide the world with better location intelligence products. If this sounds like fun, we’re hiring to build many more things — we need your help. Reach out, let’s grab a coffee, and come join us.

And if you’ve come this far, we’d love to hear from you.

--

--

Gareth Paul Jones
Foursquare

Group Product Manager @Twilio - Part-Time Crossfit Athlete.