0% found this document useful (0 votes)
5 views

Geocoding Syntax Android

The document provides instructions for geocoding in Android using Java, detailing both forward geocoding (converting an address to coordinates) and reverse geocoding (converting coordinates to an address). It includes code snippets for creating a Geocoder instance and retrieving addresses based on location names or coordinates. The examples demonstrate how to extract latitude, longitude, and address lines from the Geocoder results.

Uploaded by

nihalpatil0021
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Geocoding Syntax Android

The document provides instructions for geocoding in Android using Java, detailing both forward geocoding (converting an address to coordinates) and reverse geocoding (converting coordinates to an address). It includes code snippets for creating a Geocoder instance and retrieving addresses based on location names or coordinates. The examples demonstrate how to extract latitude, longitude, and address lines from the Geocoder results.

Uploaded by

nihalpatil0021
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Geocoding in Android (Java)

1. Forward Geocoding (Address to Coordinates)

// Create a Geocoder instance


Geocoder geocoder = new Geocoder(context);

// Retrieve a list of addresses from a location name (e.g., "New York")


List<Address> addresses = geocoder.getFromLocationName("New York", 1);

if (addresses != null && !addresses.isEmpty()) {


// Get the first address's latitude and longitude
double latitude = addresses.get(0).getLatitude();
double longitude = addresses.get(0).getLongitude();
}

2. Reverse Geocoding (Coordinates to Address)

// Create a Geocoder instance


Geocoder geocoder = new Geocoder(context);

// Retrieve a list of addresses from latitude and longitude


List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);

if (addresses != null && !addresses.isEmpty()) {


// Get the address line from the first address
String addressLine = addresses.get(0).getAddressLine(0);
}

You might also like