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 java.util.Locale;
import android.content.Context;
import android.location.Address;

import android.location.Geocoder;

public class Main {
    public static String getNameFromLocation(final double lat, final double lng, final Context context)
            throws IOException {
        final Geocoder gc = new Geocoder(context, Locale.getDefault());
        if (Geocoder.isPresent()) {
            final List<Address> list = gc.getFromLocation(lat, lng, 1);

            if (list.size() > 0) {
                final Address address = list.get(0);
                return address.getAddressLine(0);
            }
        }
        return "Fehler, bitte manuell eintragen";
    }
}