Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Get the current location of my device [duplicate]

Possible Duplicate:
How do I get the current GPS location programmatically in Android?

I have an application in which I want to get the current location.

also I want to get the latitude and longitude so I store that and return back that position.

how can do it...

like image 567
pratik Avatar asked Mar 01 '12 04:03

pratik


1 Answers

try following code segment,

import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;

public class LocListener implements LocationListener
{
    private static double lat =0.0;
    private static double lon = 0.0;
    private static double alt = 0.0; 
    private static double speed = 0.0;

    public static double getLat()
    {
        return lat;
    }

    public static double getLon() 
    {
        return lon;
    }

    public static double getAlt()
    {
        return alt;
    }

    public static double getSpeed()
    {
        return speed;
    }

    @Override
    public void onLocationChanged(Location location) 
    {
        lat = location.getLatitude();
        lon = location.getLongitude();
        alt = location.getAltitude();
        speed = location.getSpeed(); 
    }

    @Override
    public void onProviderDisabled(String provider) {}
    @Override
    public void onProviderEnabled(String provider) {}
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {}
}
like image 93
Lucifer Avatar answered Nov 06 '22 09:11

Lucifer