Geocoding converts and reverse geo-coding
Geocoding converts and reverse geo-coding
(4M)
- Geocoding converts addresses into geographic coordinates (latitude and longitude).
- Reverse geocoding does the opposite, it converts coordinates into human-readable
addresses.
-
Geocoding:
Input:
A human-readable address (e.g., "1600 Amphitheatre Parkway, Mountain View, CA").
Process:
Uses a geocoding service or API to find the corresponding geographic coordinates (e.g.,
latitude and longitude) for the given address.
Output:
Geographic coordinates (e.g., latitude: 37.423021, longitude: -122.083739).
Reverse Geocoding:
Input:
Geographic coordinates (e.g., latitude: 37.423021, longitude: -122.083739).
Process:
Uses a geocoding service or API to find the nearest human-readable address or place name
for the given coordinates.
Output:
A human-readable address (e.g., "1600 Amphitheatre Parkway, Mountain View, CA").
Geocoding
Geocoder geocoder = new Geocoder(context);
try {
List<Address> addresses = geocoder.getFromLocationName(address, 1); // Get up
to 1 result
if (addresses != null && !addresses.isEmpty()) {
Address foundAddress = addresses.get(0);
double latitude = foundAddress.getLatitude();
double longitude = foundAddress.getLongitude();
Toast.makeText(getApplicationContext(),"Latitude: " + latitude + ", Longitude: "
+ longitude,Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(),Toast.LENGTH_LONG).show();
}
} catch (IOException e) { }
Reverse Geocoding
Geocoder geocoder = new Geocoder(context);
long latitude=1430000;
long longitude=145000;
try {
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1); //
Get up to 1 result
if (addresses != null && !addresses.isEmpty()) {
Address foundAddress = addresses.get(0);
Toast.makeText(getApplicationContect(),"Address: " +
foundAddress.getAddressLine(0),Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContect(),"No address found.",
Toast.LENGTH_LONG).show();
}
} catch (IOException e) { }