Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: how to singleUpdate location & can't get location after reboot
    primarykey
    data
    text
    <p>i'm working on app, which must get latitude and longitude. in my case <code>requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener)</code> is not in option. why? because i must get location just when user do something that location is needed (let's say he hits button). and i need location exactly on the time, when button is hit. in <code>requestLocationUpdates</code>, we can set minTime-if i set this let's say on 30000 the location at the "button hit time" won't be as good as i want. of the same reason minDistance is also not as good as i want. if i understant function requestLocationUpdates correct-when minTime and minDistance are set to 0, location is updating all the time. please correct me if i'm wrong. app is for company that i'm working at and that app will be used through the day and night. so if app will check for location updates all the time, battery would be often empty. that's why i need location just at the time, that button is hit. users are not having access to internet and gps. so i must use <code>NETWORK_PROVIDER</code> </p> <p>I also have problems with getting location after reboot device. it doesnt work until i run google maps. users wont have avalible this either, so what function do google maps on android use to get location after reboot?</p> <p>at the moment i use this code: </p> <pre><code>LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); LocationListener mlocListener = new MyLocationListener(); mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mlocListener); mlocManager.removeUpdates(mlocListener); public class MyLocationListener implements LocationListener{ @Override public void onLocationChanged(Location loc){ latitude=loc.getLatitude(); longitude=loc.getLongitude(); Text = "My current location is: \n" + "Latitud = " + loc.getLatitude() + "\nLongitud = " + loc.getLongitude(); Toast.makeText( getApplicationContext(),Text,Toast.LENGTH_SHORT).show(); } @Override public void onProviderDisabled(String provider){} @Override public void onProviderEnabled(String provider){} @Override public void onStatusChanged(String provider, int status, Bundle extras){} } </code></pre> <p>code is from <a href="http://www.firstdroid.com/2010/04/29/android-development-using-gps-to-get-current-location-2/" rel="nofollow">here</a></p> <p>but this code is not working right. if i press "get location button" the Toast is shown and location is correct. but then if i press button several times, it does nothing. -but after 5 minutes Toast is shown like hundred times... why is that? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload