How to set the Draggable Map View in Android?

Share now

When developing a map focused customized Android Mobile App Development Company in Chennai, you will want your users to select an accurate location. Mostly you can use Google Maps API, which is robust and accurate.

Wondering How to set the Draggable Map view in Android? To do so, you got to select a location on the google map using draggable markers in the Google Search API.

How to set the draggable Map view in Android - Lia Infraservices - Mobile app development company in Chennai

Draggable Map in Android is a Google Map API. Determine your starting point on the map by clicking on the “current location” or change the location by dragging the pointer from the current location to your desired location anywhere on the map. 

What is onMapReady Method?

onMapReady() method will automatically locate the user’s current location on the map.

Draggable Maps helps the users to select the map pointer to any accurate location they want to check. To do this “Google Search API” will be handy for the Android platform.

The onMapReady() method initializes the map and places the user on their current location of the Google map.

The most notable point here is the draggable(true) on the MarkerOptions() and the initialization of the startMarker to the map. Setting draggable to true makes the marker draggable and vice versa is true. Now with this, after the marker is shown, you can long-press the marker then drag it to your preferred location. Also, note that this is possible because if you can see on the map initialization we added a marker drag listener.

What is the role of Google Coordinates?

Role of Google Coordinates - onMapReady method - Lia infraservices - Android App Development company in Chennai.

To understand the user’s exact current location, “Google Coordinates” will be the only choice. With the knowledge on the Google coordinates between the two points A & B, you can find,

  1. The distance between two points.
  2. The time it takes to travel from one point to another.  

Google Place Search API:

Narrowing the Map further down, we call it “Google Place Search API”.

Google place Search API - Custom mobile App Development Company in Chennai

Google Place Search API may not be the right choice to go only with Google Coordinates. Instead, you can drag and drop the map pointer to your desired location to gather the information you are looking for.

Steps to Set-up Draggable Google Map view API on Android?

Follow the points,

To set up the Draggable Google Map API on an Android Device from Google API Console

1. Create NewMapActivity.java from Google sample

Steps to Set-up Draggable Google Map view API on Android - Create NewMapActivity.java from Google sample

2. Create Application & Key-in Google API to render the map.

Create Application & Key-in Google API to render the map.

3. Enable API for – Google Maps & Google Place Android API.

 Enable API for - Google Maps & Google Place Android API

4. Get API Key from Create Credentials

Get API Key from Create Credentials

5. Insert Google Maps API Key.

 Insert Google Maps API Key

6  Run the sample to load the map Successfully.

Steps to get Google Coordinates info on the map?

To get the google map coordinates on a particular fixed location, just drag the Google Map and place the pointer where you want to find the coordinates.

1. Create instance Google Map on “GoogleMap.OnCameraldleListener”

Create instance Google Map on "GoogleMap.OnCameraldleListener"

2. Create object “LatLng” inside “onCameraIdle() method”. Which gives current pointer longitude and latitude coordinates.

Create object LatLng inside onCameraIdle() method

3. Create an instance of the “Geocoder” class.

Create an instance of the Geocoder class.

4. Create “addressList” associated with “Geocoder instance” by placing coordinates.

Create addressList associated with Geocoder instance by placing coordinates.

5. Get address, country and other info from addressList.

Get address, country and other info from addressList

6. Now get addressList and GetCountryname to be used where ever needed.

Code to get addressList and GetCountryname to be used where ever needed

Now your Draggable Google Place API is configured!

What you can do with the Draggable Map view API on Android?

Step 1 : Search Place

Search address - draggable google map view - liainfraservices

Step 2 : Pick Address

pick-address-draggable-google-map-view-api-liainfraservices

Step 3 : Find Distance & Time Duration between points on Map

find distance and time duration between two points - draggable google map view on android - liainfraservices

Conclusion:

Contact Lia infraservices – The expertise in Android and iOS Mobile App Development Company in Chennai. We create a custom android app development company in Chennai that fits the global market clients specific business requirements. We create impactful mobility solutions with highly performing Android Mobile Application Development.

Check out how we made an Android & iOS Mobile App!

April 5, 2021
Was this article helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *