Apps How to find Latitude and Longitude of the given address or City name ?

Hi,
Can u tell me how to get Latitude and Longitude of the given Name of the City or Address?

For Example :

Suppose, I enter Delhi, then It should return latitude or Longitude of it.


Thanks and Regards,
Andy
 

alostpacket

Over Macho Grande?
I dont know the answer to this but am curious myself -- could be very helpful. I wonder if there is an open source /free database out there people could use to look the info up?

If you find out the answer please let us know too :D
 

Arthur Andy

Newbie
Thread starter
Hi,
I got my answer, I put my answer here and I hope it will help others too.

Note: Here, pass address and will get Latitude and Longitude of that address. It is working fine for me.

searchedAddress --> Can be (city name/address/Zipcode).

================================================================
public boolean getLatitudeAndLongitudeFromGoogleMapForAddress(String searchedAddress){

Geocoder coder = new Geocoder(IPlant.iPlantActivity);
List<Address> address;
try {

address = coder.getFromLocationName(searchedAddress,5);
if (address == null) {
Log.d(TAG, "############Address not correct #########");
}
Address location = address.get(0);

Log.d(TAG, "Address Latitude : "+ location.getLatitude();+ "Address Longitude : "+ location.getLongitude());
return true;

}catch(Exception e){
Log.d(TAG, "MY_ERROR : ############Address Not Found");
return false;
}
}

==================================================================


Enjoy !!!
Andy
 

jonbonazza

Android Expert
You need to ensure a few things first:

1) the manifest has coarse location permission (and optionally fine location as well)
2) the device has location enabled (coarse--wifi-- should be sufficient, but you can turn on fine--GPS--if you wish as well).
 
Hi,
I have question. Are you working with googlemaps api? I am working on that and I need some help in that. See the thread I posted and can you suggest me something if have one.
Thanks,
chanukya
 

Joydip

Lurker
Actually i have new in android so i can't find the way...
I want to do this when i enter the name of the address in android Edittext then automatically the position will show in the google map..
<EditText
android:id="@+id/source"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="Source Address"
android:inputType="textPostalAddress" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search"
android:eek:nClick="doClick"/>
that is the edittext in android xml....
public void doClick(Context context,Location loc)
{
MapView mapView = (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
EditText editText = (EditText) findViewById(R.id.source);
List<Address> message = (List<Address>)editText.getText();
double latitude;
double longitude;
loc.getLatitude();
loc.getLongitude();
latitude=loc.getLatitude();
longitude=loc.getLongitude();
Geocoder gc = new Geocoder(this,Locale.getDefault());
try {
message = gc.getFromLocation(latitude,longitude,1);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MapController mc = mapView.getController();
GeoPoint geoPoint = new GeoPoint((int)(latitude * 1E6), (int)(longitude * 1E6));
mc.animateTo(geoPoint);
mc.setZoom(15);
mapView.invalidate();
}
that is my code in Activity....
plz help me...or giving me the code by which i can get my point:thinking:
 
Top