Android Google Map Search Location using Geocoder

In the previous tutorial of Android Google Map and Android Google Map Displaying Current Location we described about display basic Google Map and current location respectively.

Now in this tutorial we will implement location search functionality in Google Map.

Searching location in Google Map API is done through Geocoder class. Geocoder class is used to handle geocoding and reverse geocoding.

Geocoding is a process in which street address is converted into a coordinate (latitude,longitude). Reverse geocoding is a process in which a coordinate (latitude,longitude) is converted into an address.

Methods of Geocoder class

  1. List
    getFromLocation(double latitude, double longitude, int maxResults):
    This method returns an array of Address which specifies the surrounding latitude and longitude.
  2. List
    getFromLocationName(String location, int results, double leftLatitude, double leftLongitude, double rightLatitude, double rightLongitude):
    This method returns an array of Address which describes the given location such as place, an address, etc.
  3. List
    getFromLocationName(String location, int results):
    This method returns an array of Address which describes te given location such as place, an address, etc.
  4. static boolean isPresent(): This method returns true if the methods getFromLocation() and getFromLocationName() are implemented.

Let's see the code which convert location name into coordinate.

Example of Android Google Map API Searching Location

Let's see an example of Google Map which search input location.

activity_maps.xml

Add a fragment (SupportMapFragment), EditText and Button in activity_maps.xml file.

build.gradel

Add the following dependencies in build.gradel file.

MapsActivity.java

Add the following code in MapsActivity.java file.

Required Permission in AndroidManifest.xml

Add the following user-permission in AndroidManifest.xml file.

AndroidManifest.xml

Output

android Search Location 1
android Search Location 2
android Search Location 3




Contact US

Email:[email protected]

Search Location
10/30