get Geo Point From Address - Android Map

Android examples for Map:Address

Description

get Geo Point From Address

Demo Code


//package com.java2s;

import java.util.List;

import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;

public class Main {
    public static Location getGeoPointFromAddress(Context ctx,
            String strAddress) {/*  w w w  .  j  av a  2 s  .c o m*/
        Geocoder coder = new Geocoder(ctx);
        List<Address> address;

        try {
            address = coder.getFromLocationName(strAddress, 5);
            if (address == null) {
                return null;
            }
            Address location = address.get(0);
            location.getLatitude();
            location.getLongitude();

            Location loc = new Location("");

            loc.setLatitude(location.getLatitude());
            loc.setLongitude(location.getLongitude());

            return loc;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related Tutorials