android - Get last location latitude and longitude -
this code.
public class mylocationlistener implements locationlistener { @override public void onlocationchanged(location loc) { location location = getlastknownlocation(locationmanager.network_provider); lastlocationlat = location.getlatitude(); lastlocationlongi = location.getlongitude(); locationlat = loc.getlatitude(); locationlongi = loc.getlongitude(); if(loc.hasspeed()) { float myspeed = loc.getspeed(); toast.maketext(getapplicationcontext(), ""+myspeed, 2000).show(); } } @override public void onproviderdisabled(string provider) { toast.maketext(getapplicationcontext(), "gps disabled", toast.length_short).show(); } @override public void onproviderenabled(string provider) { toast.maketext(getapplicationcontext(), "gps enabled", toast.length_short).show(); } @override public void onstatuschanged(string provider, int status, bundle extras) { toast.maketext(getapplicationcontext(), "gps onstatuschanged", toast.length_short).show(); } }
but did not last location in code got same latitude , longitude
you using locationmanager.network_provider locations. code implies want gps ("gps disabled")? in case should use locationmanager.gps_provider.
locationmanager.network_provider not accurate (few hundred meters if locking cell towers), might not detect location change if move less 100m.
on other hand, gps unavailable indoors or between tall buildings. gps uses power should not used time (when app in background).
read obtaining user location, best approach getting location regards accuracy vs service availability.
Comments
Post a Comment