Google Maps Nearby Places API using Retrofit Android

Skip links

Main navigation

Google Maps Nearby Places API

Hello Guys. Hope all of you are doing well. In this tutorial, we will learn how to add the markers on nearby places in Google Maps API using . We will name this App as Google Maps Nearby Places API. You can see demo of this tutorial in above video. This is one of the most crystal clear tutorials where minimum code is used to implement nearby places app using retrofit. We made a similar tutorial on

but that was implemented using Async Task. Now Async task has become pretty much mediocre and people are using Retrofit to capture data from URL, So we made this tutorial on similar lines. Now you don’t have to make any JSON Parser or Data capture class. Retrofit Android automatically takes care of it. All the people who do not know how to use Retrofit Android can see our tutorial of .

1) Android Studio installed on your PC (Unix or Windows). You can learn how to install it .

2) A real time android device (Smartphone or Tablet) .

3) A basic knowledge of

& functions used in Android Studio.

Before going through this post we will suggest you to first have a look at our post on . That information (inside link) will be used in this post.

Now let’s make it. We hope you would have already made an . So we are not repeating that part now. Also if you don’t want to learn Retrofit then you can refer our tutorial of

where we have used Async Task to implement exactly same tutorial.

Please follow following steps:

Open Android Studio and make a new project with name “Google Maps Retrofit” or “Google Maps Nearby Places API” and company domain application.example.com (I used my company domain i.e androidtutorialpoint.com. Similarly you can use yours).

Click Next and choose android version Lollipop. Again Click Next and Choose Google Maps Activity

(as shown in following pic).

Leave all things remaining same and Click Finish.

Now you will be able to see three files:

google_maps_api.xml (…/GoogleMapsSearchNearby/app/src/debug/res/values/google_maps_api.xml)

MapsActivity.java (…/GoogleMapsSearchNearby/app/src/main/java/com/androidtutorialpoint/googlemapssearchnearby

/MapsActivity.java)

AndroidManifest.xml ( …/GoogleMapsSearchNearby/app/src/main/AndroidManifest.xml)

Open google_maps_api.xml. Here you will find a lot of information along with a link. Copy-Paste this link in your web browser. Make a Gmail account through which you will configure google play services.

Now at the browser choose “Create New Project” and Click Continue. Following screen will be displayed:

Click on Go to credentials. Below screen will appear.

Create your key by clicking Create. Now a key will be created but there is one big change here as compared to our previous Google Maps tutorials. Here you will need a Server Key. So to generate a Server Key click on Create Credentials and then API Key as shown in the following image:

Click on Server Key. Below screen will appear:

Click Create and copy the Server Key generated. You shall copy and paste this key in google_maps_api.xml. Copy paste it in place where YOUR_KEY_HERE is written:

Code inside google_maps_api.xml is complete.

google_maps_api.xml

LVwrKoLOEMgwUBXGiut0bkFhoAjOiaVemoMlymg

If you go inside AndroidManifest.xml then this key will be displayed in meta tags. Here you need to add permissions for accessing location of device. The required permission should be as follows:

ACCESS_NETWORK_STATE – To check network state i.e if we are connected to any network or not.

INTERNET – If we are connected to Internet or not.

ACCESS_COARSE_LOCATION – To determine user’s location using WiFi and mobile. It will give us an approximate location.

ACCESS_FINE_LOCATION – To determine user’s location using GPS. It will give us precise location.

OpenGL ES V2 – Required for Google Maps V2

AndroidManifest.xml

Here we will add three buttons each for Restaurant, Hospitals and Schools such that when user clicks on Restaurant then markers will be added on nearby restaurants. Similarly in case of other two buttons. For this, we will use . Refer below code:

activity_maps.xml

Read More Post

STAY CONNECTED

Most Popular

Why Serviced Apartments Are the Perfect Choice for Long-Term Stays in Singapore – Everything You Need to Know
17 Dec

Why Serviced Apartments Are the Perfect Choice for Long-Term Stays in Singapore – Everything You Need to Know

If you’re heading to Singapore for a few weeks or many months, maybe for work or study or just to

Manifesting Your Dream Career: Finding Your Passion And Purpose
01 Aug

Manifesting Your Dream Career: Finding Your Passion And Purpose

Are you passionate about finding your dream career? Manifesting can help you align your career with your passions and purpose.

Revolutionizing Your Ride: Expert Auto Service At Carolina Auto Service
27 Feb

Revolutionizing Your Ride: Expert Auto Service At Carolina Auto Service

Finding a reliable auto service provider is paramount in the bustling world of vehicle maintenance and repair. That's where Carolina

Floratam: The Robust Grass Solution From Council Growers SOD
25 Jan

Floratam: The Robust Grass Solution From Council Growers SOD

Floratam grass, a popular St. Augustine variety, has become a go-to choice for homeowners and landscapers seeking a lush, durable

Carolina Mobile Autoservice: Your Go-To For Expert Brake Service Repair
25 Jan

Carolina Mobile Autoservice: Your Go-To For Expert Brake Service Repair

For vehicle owners, the braking system is among the most critical components for safety and performance. Carolina Mobile Autoservice, a

Safeguarding Your Property: Expert Water Damage Services By MBC Capital
24 Jan

Safeguarding Your Property: Expert Water Damage Services By MBC Capital

Water damage can significantly impact homes and businesses, often leaving a trail of destruction and disruption in its wake. Understanding