get Longitude From Address - Android Map

Android examples for Map:Latitude Longitude

Description

get Longitude 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 getLongitudeFromAddress(String findAddress,
            Context context) {/* w ww.j  av a  2  s  .  c om*/

        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.getLongitude();

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

Related Tutorials