1

I am working in android. i want to get GPS coordinates of my android device.

I am using this code to get my coordinates:-

LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 


Location location = mlocManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

            if(location!=null) {
               myLongitude = location.getLongitude();
               myLatitude= location.getLatitude();
            }
            else {
               myLongitude =0;
               myLatitude= 0;
            }

           LocationListener mlocListener;
           mlocListener = new MyLocationListener();
           mlocManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, mlocListener);

and this the class:-

 public class MyLocationListener implements LocationListener
 {
    @Override
    public void onLocationChanged(Location loc)

    {
        myLatitude= loc.getLatitude();
        myLongitude=loc.getLongitude();
    }
}

but all the time i get latitude and longitude to zero only. please suggest me what mistake i have done.

Thank you in advance.

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
Pushpendra Kuntal
  • 6,118
  • 20
  • 69
  • 119
  • 1
    Will this help? http://stackoverflow.com/questions/3145089/what-is-the-simplest-and-most-robust-way-to-get-the-users-current-location-in-a/3145655#3145655 – Ghost Dec 15 '11 at 06:50
  • you want co-ordinate using Network provider in device or in emulator? – Pratik Dec 15 '11 at 06:59

1 Answers1

0

Make sure you put the permission in Manifest

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
sampathpremarathna
  • 4,044
  • 5
  • 25
  • 37