Hey guys, I want to get the latitude and longitude of the users' location. I have tried to overflow the developers site and stack, some examples are loaded on the user who runs something: - onLocationChanged () I do not need location updates, the user can now take a minute or two minutes Will need to know the location of the time i started the location and what if the user has never used any geographic location app before, then i Also would like an option for LocationManager.getLastKnownLocation ()
My code is: -
Location Manager LM = (Location Manager) getSystemService (context.LOCATION_SERVICE); // Connect to GPS location service location public = lm.getLastKnownLocation (lm.NETWORK_PROVIDER); Toast. Make text (current location, "latitude ->" + double.toastring (loc.getLatitude (+) + "longitude -> gt; double +string (loc.getLongitude ()), toast .LENGTH_LONG ) Showing (); and is working fine but I'm afraid that getLastKnownLocation may be zero when the first time it is used.
Thanks
Sign up for location updates and once you first If you receive the update, you can cancel the registration for future updates.
In other words, create a LocationListener and assign it to your location manager 's request location update method. In the onLocationChanged your LocationListener , call the removeUpdates method to your LocationManager , this parameter. Before you take some time to get a new position, but there is actually no alternative to using getLastKnownLocation .
Comments
Post a Comment