android-location

How to get location when it changes

六月ゝ 毕业季﹏ 提交于 2019-12-04 05:26:00
问题 I would like to know there is a way to get location if only it changes? I know android provides this http://developer.android.com/training/location/receive-location-updates.html to get location updates and as it states: "If your app does navigation or tracking, you probably want to get the user's location at regular intervals. While you can do this with LocationClient.getLastLocation(), a more direct approach is to request periodic updates from Location Services. In response, Location

Is it possible to get a notification when any location provider is enabled/disabled and ascertain what action occurred?

旧街凉风 提交于 2019-12-04 02:18:29
I wish to receive a notification when the user enables or disables either Network or GPS locations, and importantly I wish to know which one they have changed and how. I have a broadcast receiver for the android.location.PROVIDERS_CHANGED broadcast intent and this is receiving the correct broadcast. I now need to try and determine which action has occurred i.e. enable or disable and which provider has been changed. I know that I could keep the state of each provider and then when I receive notification that they have changed then I could work out what has changed, I am looking for a more

Why is locationmanager returning old location fixes with new gettime-timestamp?

瘦欲@ 提交于 2019-12-04 01:24:21
问题 We have an app that upon user action tries to get a location fix. It listens both on GPS and network and has a time/accuracy based decision matrix to determine when to stop listening and what fix to return. We have noticed, on occasion, a very strange behaviour. We use the classic way to see how old the fix is, like so: long age = now - newLocation.getTime(); if(age >= prefs.getLocationMaxAge()){ Log.d(TAG, "location too old."); return; } But sometimes, the location.getTime returned from the

Why can't I get the location by the NETWORK_PROVIDER as follows?

梦想与她 提交于 2019-12-03 21:54:51
It is very simple. But I see nothing appears on the logcat. @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map_selection); LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. if (location != null) { double longitude = location

Calculating Speed for a navigation app without getSpeed() method

一世执手 提交于 2019-12-03 19:04:56
问题 I am developing an app which is more of a time-shift racing between your friends. I need to calculate speed of a moving vehicle, and I don't want to use Location.getSpeed() method. (Explained in detail in the bottom why I don't want to use it) I am trying to calculate speed with the help of Latitude and Longitude available to me, and this is where I need help. The help needed: I would want to know is: If the algorithm is correct Should I calculate in Centimeters instead of meters And if there

Location Manager remove updates permission

£可爱£侵袭症+ 提交于 2019-12-03 13:12:29
I am using android studio and compileSdkVersion is 23 in that i am using below code if(locationManager != null){ locationManager.removeUpdates(GPSListener.this); } to stop gps update where GPS Listener is a class which implements LocationListener. but in removeUpdates line i am getting below lint warning Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission ) or handle a potential SecurityException I am not getting what is the issue in the above code. Any extra permission need to be added in manifest file?.

getLastKnownLocation() always return the same location

偶尔善良 提交于 2019-12-03 12:52:48
I'm tring to get the location from the gps/netwrok by best provider but always it's return the same location, also i can see that on google map there is a sign to my right location. please anyone can tell me what i'm doing wrong? My activity is: public class MainMenu2 extends Activity implements LocationListener, OnClickListener on my onCreate i have: if(isGooglePlay()){ setContentView(R.layout.menu_2); setUpMapIfNeeded(); } isGooglePlay method: private boolean isGooglePlay() { // looks if googlemaps is available int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if

Android Geofence not triggers once location OFF and ON again [duplicate]

我的未来我决定 提交于 2019-12-03 09:05:59
This question already has an answer here: How to check if Location Services are enabled? 18 answers I am using Android Geofencing API.After add geofence it works fine when location is ON.But If I OFF location and ON again,afterwards Geofencing not triggers when enter or exit.I have tested on my Moto G with Android 5.0.2 device. Is it Geofence will expire If location is off? I have seen on Android document as, In case network location provider is disabled by the user, the geofence service will stop updating, all registered geofences will be removed and an intent is generated by the provided

When should I use ACCESS_COARSE_LOCATION permission?

坚强是说给别人听的谎言 提交于 2019-12-03 07:21:14
问题 I am building an Android app that will track the user's geolocation and draw their route on a map. I am using the Google Play Services location API, as described here. It is intuitive that my application requires the ACCESS_FINE_LOCATION permission, which I put in the manifest: <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> Do I also need the ACCESS_COARSE_LOCATION permission? What's the use case where I need the coarse location? 回答1: Do I also need the ACCESS

What is the difference between shouldShowRequestPermissionRationale and requestPermissions?

点点圈 提交于 2019-12-03 06:52:26
I am building an app that requires user location. I am following the Android training documentation from here which says: shouldShowRequestPermissionRationale return the boolean indicating whether or not we should show UI with rationale for requesting a permission (dangerous permission, ACCESS_FINE_LOCATION) Now in this code (taken from the documentation itself) : if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,