tags:

views:

51

answers:

1

I wanna draw a route on the basis of the entered source & destination address. I need to get lat/log on the basis of address to draw a map in android. So how can i get lat/log on the basis of entered address.

 Geocoder geoCoder = new Geocoder( getBaseContext(), Locale.getDefault());
 try {
     List<Address> addresses = geoCoder.getFromLocationName("Loc",1);
     String add = "";
     if (addresses.size() > 0) 
     {
         add = addresses.get(0);
     }

     Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();
 } catch (IOException e) {                
     Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
 }
+1  A: 

Use the Google Geocoding API to get coordinates for an address: http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding

TuomasR
Thanx for reply, But using Geocoding, I am getting IOExcetion.
Sandy
How are you using it and what's the exact exception. Post source in your original question?
TuomasR
addresses is null
Sandy
"addresses is null" must be `NullPointerException`, man.
Albus Dumbledore
Ya, But why am i not getting addresses??
Sandy
Check out the doc: http://developer.android.com/reference/android/location/Geocoder.html#getFromLocationName(java.lang.String, int, double, double, double, double) It states that null is returned if no coordinates are found. You are searching for "Loc", which most likely returns... well... nothing. Try it with an actual address, such as "1600 Amphitheatre Parkway, Mountain View, CA"
TuomasR
I have entered actual address still its givig same IOException and message is : "Service is not available".
Sandy
Sandy