Places search and Cab Booking Apps

Prakhar Srivastava
Jul 10, 2017 · 5 min read

Download apk

All of us have used apps like Uber and Ola and find it really fascinating. The smooth process of booking a cab using the apps is a very happy experience. And the biggest facility these apps provide is places search and marking on the map. So you don’t have to write the full address as it auto completes it and also you can be sure if the address picked up by it is correct or not by looking at the map.

Today we’ll be building the same functionality where one can search the places and select it, marking it on map and getting every detail of the place available on google.
Let’s look at what are we building today :

It looks excellent and yet it is very easy..
Let’s divide our solution in three parts :

  • Non coding part (Using Google Api Console).
  • Loading Map on screen (surprisingly it takes only a minute.. yes! that simple, thanks to android studio)
  • Places search functionality.

So let’s start building.

Using Google Api Console

For using google maps in our application, we have to create an API key on the google developer’s console. This API key is later placed in our app and users can see maps in our app. So let’s create the key.

  • Create a new Project on Developer’s console

Click on the add icon on top and when it prompts, provide a project name and continue.
Once the project is created, it will take you directly to the dashboard.

  • Now on the top, we can see the button for Enable APIs. Click on that button.

Now after clicking on that Button, we can see a lot of APIs listed. We have to select the Maps and Places API for android under Google Maps API section and click on enable.

  • Once the APIs are enabled, from the dashboard or library screen, we migrate to credentials screens.
  • After clicking the Credentials, on the next screen, We’ll click
    Create Credentials > API key
    And copy the API key somewhere, may be on a text file (we’ll be needing this key shortly).

That’s all. Now we have created the project, enabled the APIs and generated an API key to use.

Now let’s move to the coding part and create a project in android studio.

Create and load map on screen.

Everytime we create a new project in Android Studio, we create an activity, remember? So this time while creating the project, we’ll select the GoogleMapsActivity option.

Now sit back, relax, eat some cheetos, grab some coffee may be and let the gradle build.
When the gradle build is completed, the file google_maps_api.xml should be visible on screen. If it is not, open it from the location Res > Values > google_maps_api.xml.

When the xml is opened. Put the API key that we created a minute back in place of API_KEY_HERE. And it should look like

ignore the asterisks above and put your full key in place of it.

DONE! run your app on device and you should see the map and a marker in Sydney. The Marker in Sydney is shown because it is hard coded in the MapsActivity.java by default.

is the function that is called when the map is loaded and ready for any operations. So Android Studio by default puts a marker on Sydney when Map is ready.

Places Search Functionality

First things first.. add the following library from google in build.gradle.
It is used for searching the places that we type.

Now the UI.
When we created the project, the activity_maps.xml included only a fragment over which the map is loaded. So that fragment takes full screen.

So now we’ll put the fragment in a relative layout along with an EditText. So the fragment still takes the full screen but now we have an EditText over it (Since both are in a single RelativeLayout). So our layout looks like this :

We have EditText to search for the places. But it doesn’t search for anything written in the EditText (trust me!).
Actually, on click of the EditText, a fragment is loaded where we search. This fragment is loaded by google only, we don’t need to make this fragment in our design.

So the only thing we need to do is fire the intent on EditText click.

Now we can search and select any place that is on google.
But after the selection we need the details of the page back. How do we do that?
Simple, we override the and get the place details. Once we have details, we mark it on the map using the marker.

That’s all. Now run the app and it should work perfectly.

Some important functions that the places API provide are:

Try putting these in and look what you get.

I have included the Sample Project that is really easy. Just replace my key with yours and you can get it working. You can also see the app in action before trying, just to see how it looks, by downloading the apk for which I have provided the link.

Full Source Code

Download apk

May the source be with you.

Prakhar Srivastava

Written by

A programmer, musician, reader and a believer. Love to be part of solutions. If you need help solving any real life problem through technology, hit me up :)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade