-1

I am working on an app that calculate the distance between 2 points but i don't now how to get the current position.I'm using a google maps activity.

Any help would be greatly appreciated.

The code:

LocationManager service = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria(); 
String provider = service.getBestProvider(criteria, false); service.requestLocationUpdates(provider,1000,0,locationListenerGPS); Location location = service.getLastKnownLocation(provider); 
LatLng userLocation = new LatLng(location.getLatitude(),location.getLongitude());
Rainmaker
  • 10,294
  • 9
  • 54
  • 89
  • post your code here please – Quick learner Jun 18 '18 at 16:42
  • I suggest you use Google to research the Android Location Services API. – Code-Apprentice Jun 18 '18 at 16:42
  • i use this code but it retun null: – Patrick Pigna Jun 18 '18 at 16:45
  • LocationManager service = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider = service.getBestProvider(criteria, false); service.requestLocationUpdates(provider,1000,0,locationListenerGPS); Location location = service.getLastKnownLocation(provider); LatLng userLocation = new LatLng(location.getLatitude(),location.getLongitude()); – Patrick Pigna Jun 18 '18 at 16:45
  • You can refer to this link to find out the answer to your question https://stackoverflow.com/questions/21403496/how-to-get-current-location-in-google-map-android – xPain Jun 18 '18 at 17:02

1 Answers1

0

Use the documentation for this . LocationManager is not the best way. Use GooglePlayServices.

Check out the step by step way in the official docs

Rainmaker
  • 10,294
  • 9
  • 54
  • 89