Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Given a latitude and longitude, Get the location name

Tags:

I am developing an application wherein I get the latitude, longitude in my android device and post them to a web server.

and in a web application I show the location details with the help of google maps.

Here I have huge collection of lat long values which i loop it in my jsp and create multiple markers with info windows.

Now the problem is that I need to show the location name of the particular latitude and longitude in the Info Window of google maps.

Can anyone help me with the google maps script or how can i get the location name from the lat long values in my android phone itself, so that I can post that to my web server.

like image 803
Krishna Avatar asked May 30 '11 05:05

Krishna


People also ask

How do I get a city name from Geocoder?

From a Geocoder object, you can call the getFromLocation(double, double, int) method. It will return a list of Address objects that have a method getLocality() .


Video Answer


1 Answers

Here i am given a single just pass the latitude and longitude in this function then you got all the information related to this latitude and longitude.

public void getAddress(double lat, double lng) {
    Geocoder geocoder = new Geocoder(HomeActivity.mContext, Locale.getDefault());
    try {
        List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
        Address obj = addresses.get(0);
        String add = obj.getAddressLine(0);
        add = add + "\n" + obj.getCountryName();
        add = add + "\n" + obj.getCountryCode();
        add = add + "\n" + obj.getAdminArea();
        add = add + "\n" + obj.getPostalCode();
        add = add + "\n" + obj.getSubAdminArea();
        add = add + "\n" + obj.getLocality();
        add = add + "\n" + obj.getSubThoroughfare();

        Log.v("IGA", "Address" + add);
        // Toast.makeText(this, "Address=>" + add,
        // Toast.LENGTH_SHORT).show();

        // TennisAppActivity.showDialog(add);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}
like image 77
DynamicMind Avatar answered Sep 25 '22 02:09

DynamicMind