get Latitude From Address - Android Map

Android examples for Map:Latitude Longitude

Description

get Latitude From Address

Demo Code


//package com.java2s;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.widget.Toast;
import java.util.List;

public class Main {
    public static double getLatitudeFromAddress(String findAddress,
            Context context) {/*from w w  w .  j av a  2s . c o  m*/

        Geocoder coder = new Geocoder(context);
        List<Address> address;

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

        } catch (Exception e) {
            Toast.makeText(
                    context,
                    "Error occured finding latitude and latitude for "
                            + findAddress, Toast.LENGTH_SHORT).show();
            return 0;
        }
    }
}

Related Tutorials