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

Geo Coding

The document discusses geocoding in Android, including forward geocoding to convert an address string to latitude and longitude, reverse geocoding to convert latitude and longitude to an address string, and requiring the INTERNET and ACCESS_NETWORK_STATE permissions in the app manifest.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Geo Coding

The document discusses geocoding in Android, including forward geocoding to convert an address string to latitude and longitude, reverse geocoding to convert latitude and longitude to an address string, and requiring the INTERNET and ACCESS_NETWORK_STATE permissions in the app manifest.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Geocoding

import android.location.Address;
import android.location.Geocoder;

// Address string
String addressString = "1600 Amphitheatre Parkway, Mountain View, CA";

try {
Geocoder geocoder = new Geocoder(context);
List<Address> addresses = geocoder.getFromLocationName(addressString, 1);
if (addresses != null && !addresses.isEmpty()) {
Address address = addresses.get(0);
double latitude = address.getLatitude();
double longitude = address.getLongitude();
// Use latitude and longitude
} else {
// Address not found
}
} catch (IOException e) {
e.printStackTrace();
}

Reverse Geocoding

import android.location.Address;
import android.location.Geocoder;

// Latitude and Longitude


double latitude = 37.4233438;
double longitude = -122.0728817;

try {
Geocoder geocoder = new Geocoder(context);
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses != null && !addresses.isEmpty()) {
Address address = addresses.get(0);
String addressString = address.getAddressLine(0);
// Use addressString
} else {
// Address not found
}
} catch (IOException e) {
e.printStackTrace();
}

Manifest XML

<uses-permission android:name="android.permission.INTERNET" />


<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

You might also like