get Location Address With Geo Coder - Android Map

Android examples for Map:Address

Description

get Location Address With Geo Coder

Demo Code


//package com.java2s;
import android.content.Context;
import android.location.*;

import java.io.IOException;

import java.util.List;
import java.util.Locale;

public class Main {
    public static String getAddressWithGeoCoder(Context context,
            double latitude, double longitude, int maxResults) {
        Geocoder gc = new Geocoder(context, Locale.getDefault());
        try {//w  w  w. j  av a  2  s .c  om
            List<Address> addresses = gc.getFromLocation(latitude,
                    longitude, maxResults);
            if (addresses != null && addresses.size() > 0) {
                for (Address address : addresses) {
                    String temp = "";
                    for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
                        temp += address.getAddressLine(i) + " ";
                    }
                    return temp;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
        return null;
    }
}

Related Tutorials