geo code Address - Android Map

Android examples for Map:Address

Description

geo code Address

Demo Code


//package com.java2s;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import java.io.IOException;
import java.util.List;
import java.util.Locale;

public class Main {
    public static String geocodeAddress(double lat, double lon,
            Context context) throws IOException {
        Geocoder gcd = new Geocoder(context, Locale.getDefault());
        List<Address> addresses = gcd.getFromLocation(lat, lon, 1);

        if (addresses.size() > 0 && addresses.get(0).getLocality() != null)
            return addresses.get(0).getLocality();

        return "[Unidentified location]";
    }// ww  w  .  j a va 2s .com
}

Related Tutorials