I want to perform some geocoding with Android, and MonoDroid. The key issues are:
-
When you get the text value of an EditText, you are not getting a string, but an IEnumerable<char>. That's an Android-ism.
-
The Geocoder requires permission to use the internet.
-
If the lookup fails, you recieve a null.
-
The geocoder runs on the UI thread. It is not asynchronous. This is different that listening for location changes.
I looked at some Java Code to do this. I then did a translation and got this:
//There is a bug in the emulator that results in an error.
//This code works properly on a device.
var add = Convert.ToString(et.Text);
Geocoder geocoder = new Geocoder(this, Java.Util.Locale.Default);
IList<Android.Locations.Address> result = geocoder.GetFromLocationName(add, 10);
if (result != null)
{
tvLat.Text = result[0].Latitude.ToString();
tvLon.Text = result[0].Longitude.ToString();
}