Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    public static double getLonByLocation(Context context, String ciudad) {
        Geocoder geocoder = new Geocoder(context);
        try {
            List<Address> result = geocoder.getFromLocationName(ciudad, 1);
            if (result != null && result.isEmpty() == false) {
                return result.get(0).getLongitude();
            }
        } catch (IOException e) {
            return 0D;
        }

        return 0D;
    }
}