-2

So I'm trying to make a button that will show me my current longitude and latitude and show my new long and lat when I'm moving, I'm trying to do this using the google maps API. I'm trying to read through the documentation but I'm not seeing any available methods. Also, I'm new to coding for android so I don't know if the way documentation is written differs. I saw tutorials that used Location_Manager, so it had me thinking that I don't need to use Google. Please help I'm at a wall here.

1 Answers1

1

Code to fetch current GPS co-ordinates on click of a button

    LocationManager mLocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
            LocationListener mLocListener = new MyLocationListener();
            mLocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocListener);

    public class MyLocationListener implements LocationListener{        

    public void onLocationChanged(Location loc) {           
        String message = String.format(
                    "New Location \n Longitude: %1$s \n Latitude: %2$s",
                    loc.getLongitude(), loc.getLatitude()
            );
            Toast.makeText(LbsGeocodingActivity.this, message, Toast.LENGTH_LONG).show();
    }
    public void onProviderDisabled(String arg0) {

    }
    public void onProviderEnabled(String provider) {

    }
    public void onStatusChanged(String provider, int status, Bundle extras) {

    }       
}
Vikash VK
  • 21
  • 7