search Location By Name - Android Map

Android examples for Map:Location

Description

search Location By Name

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 Address searchLocationByName(Context context, String name) {
        Geocoder gc = new Geocoder(context, Locale.getDefault());
        try {/*ww  w.j  av  a2s  . c om*/
            List<Address> addresses = gc.getFromLocationName(name, 1);
            if (addresses != null) {
                Address address_send = null;
                for (Address address : addresses) {
                    address.getAddressLine(1);
                    address_send = address;
                }
                return address_send;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related Tutorials