uses Geocoder to get coordinates for location string - Android Map

Android examples for Map:Location String

Description

uses Geocoder to get coordinates for location string

Demo Code


import android.content.Context;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationManager;
import java.io.IOException;
import java.util.List;

public class Main{
    /**/*from www .jav  a 2s. c o m*/
     * uses Geocoder to get coordinates for location string
     * @param location
     * @param context
     * @return object com.mermix.model.common.Address
     */
    public static com.mermix.model.common.Address getAddressFromLocation(
            String location, Context context) {
        Geocoder gc = new Geocoder(context);
        List<Address> list;
        Address addressAndroid;
        com.mermix.model.common.Address addressCustom = new com.mermix.model.common.Address();
        try {
            list = gc.getFromLocationName(location, 1);
            for (int idx = 0; idx < list.size(); idx++) {
                addressAndroid = list.get(idx);
                addressCustom.setLatitude(addressAndroid.getLatitude());
                addressCustom.setLongitude(addressAndroid.getLongitude());
            }
        } catch (IOException e) {
            Common.logError("LocationUtils getAddressFromLocation IOException: "
                    + e.getMessage());
            //e.printStackTrace();
        }

        return addressCustom;
    }
}

Related Tutorials