get Location - Android Map

Android examples for Map:Location

Description

get Location

Demo Code


//package com.java2s;

import android.content.Context;

import android.location.Location;
import android.location.LocationManager;

public class Main {
    public static String getLocation(Context context) {

        LocationManager lm = (LocationManager) context
                .getSystemService(Context.LOCATION_SERVICE);

        Location l = lm//from w w  w.j a  va2 s.  c o  m
                .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

        String result = "";

        if (l != null) {
            result = l.getLatitude() + "," + l.getLongitude();
        }

        return result;
    }
}

Related Tutorials