I developed an application to search for a user's location using GPS.
There is no mistake. It finds the location using Wifi correctly, but in GPS mode it does not return any values. I added the required resolution to the manifest, and GPS is on.
Can someone tell me how to get location using GPS?
I have included my code here:
package cgaloation; public class UseGps extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationListener mlocListener = new MyLocationListener(); mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener); } public class MyLocationListener implements LocationListener { @Override public void onLocationChanged(Location loc) { Geocoder gp = new Geocoder(getBaseContext()); try { ArrayList<Address> address = (ArrayList<Address>) gp .getFromLocation(loc.getLatitude(), loc.getLongitude(), 1); if (address != null && address.size() > 0) { Toast.makeText(getBaseContext(), address.get(0).toString(), Toast.LENGTH_LONG).show(); } } catch (IOException e) { e.printStackTrace(); } } @Override public void onProviderDisabled(String provider) {} @Override public void onStatusChanged(String arg0, int arg1, Bundle arg2) {} @Override public void onProviderEnabled(String arg0) {} } public void onProviderEnabled(String provider) {
source share