Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get latitude & longitude from address on Android? [duplicate]

Possible Duplicate:
How can I find the latitude and longitude from address?

I want to get latitude and longitude of particular address . How can i do this ?

like image 744
diordna Avatar asked Aug 13 '12 10:08

diordna


2 Answers

private void getFromLocation(String address)
    {
          double latitude= 0.0, longtitude= 0.0;

        Geocoder geoCoder = new Geocoder(this, Locale.getDefault());    
        try 
        {
            List<Address> addresses = geoCoder.getFromLocationName(address , 1);
            if (addresses.size() > 0) 
            {            
                GeoPoint p = new GeoPoint(
                        (int) (addresses.get(0).getLatitude() * 1E6), 
                        (int) (addresses.get(0).getLongitude() * 1E6));

                latitude=p.getLatitudeE6()/1E6;
                longtitude=p.getLongitudeE6()/1E6;


                }
        }
        catch(Exception ee)
        {

        }
    }
}
like image 127
Kamal Avatar answered Oct 05 '22 11:10

Kamal


You can get from the below code,

private void GetLatitudeAndLongitude() {
    geocoder = new Geocoder(mContext, Locale.getDefault());
    try {
        List<Address> addresses = geocoder.getFromLocationName(txtLocation.getText().toString().trim().toLowerCase(), 1);
        if (addresses.size() > 0) {
            homeInfoModel.setLalitude(String.valueOf(addresses.get(0).getLatitude()));
            homeInfoModel.setLongitude(String.valueOf(addresses.get(0).getLongitude()));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
like image 22
user Avatar answered Oct 05 '22 11:10

user