I wrote listener which is getting data from sensor gps(like lon lat etc).
I wrote listener which is getting GNSSStatus and calculate constalation.
But now how can i know from which constalation(galileo/gps/glonas/...)?
I can't use update flag in one listener to gain data from second couse when screen is off that work bad secondary when it can't be sure from which satelite current i took data on listener onLocationChanged(first listener).
So how can i merge that for get information from what constalation get data.
Related
I've implemented a foreground service for giving me the current location every 10 seconds. With the collected data I want to display a route on the map.
However, when dealing with location tracking and services, the screen of the phone won't be always on, because of battery saving. So the activity will call onPause(), onStop() methods and the earliest point for the MapView update will be after onResume(). Up to this moment on every broadcast to the activity I send the list of all LatLng objects, clear the route up to this moment and display again the route using a Polyline
It does the job, but somehow I find it very inefficient, speaking of system resources.
Alternative will be on every broadcast to save the received LatLng objects in a list like List<LatLng> points=new ArrayList<LatLng>(); initialized in the activity, and for displaying the data, computethe difference between the received coordinates and those who are already saved in the Activity's List, and display only those to the Polyline.
What do you think? Is there also a better approach than these two?
Firstly, i have to mention stackoverflow is about a question regarding code optimizations, bugs, software problems and solutions not ideas.
A foreground service every 10 seconds will be expensive regarding CPU and battery. With that being said, there are a few ways you can go around this:
// Store data in somekind of database
1- SQLite (On the phone not recommended as writing and reading database values can take alot of time and be resource-extensive)
2- Firebase(Remote best option)
3- SharedPrefernces(On the phone but single key-value pairs works for your case )
Firebase tutorial : https://www.androidauthority.com/create-a-gps-tracking-application-with-firebase-realtime-databse-844343/
//To minimize resource usages instead of a foreground service consider but try to increase your time between requests.
1-AlarmManger
2-setWindow
3-setExact
Finally, please do not remove your old polyline and create a new one as graphics are memory and battery enemy. just do something like:
LatLng somePoint = new LatLng(location.getLatitude(), location.getLongitude());
//Then add this point to the existing `polyline`:
List<LatLng> fullPointList = somePolyLine.getPoints();
fullPointList.add(somePoint);
somePolyLine.setPoints(fullPointList);
Set the unique id for your current route. When the service is running, store the points to the DB. Then broadcast your event (may be with your current route id) and load them separately from your Activity to get the points.
I have a google map fragment set up in my activity and an onLocationChanged() and getLastKnownLocation running in coherence with it.
However when i run my application , my map points to the right city and everything but the location is off from the original location by about a few km or so .
To understand why this was happening ,
I tried the following
1. Used the Button to reset the location with the location update
2. Logged my Location
3. Waited for the interval to reset my location
In all these cases my actual location was the end result either in the map or in the log with no significance of the fake location anywhere in the log .
So i set up a camera changed listener to understand the new location and acquire the coordinates but the coordinates it gave had a much higher precision than the original coordinates and im guessing somehow the problem arises when the coordinates are parametrised into the latlng class.
Ex:
Normal:
xx.xxxxxxx xx.xxxxxxx
Camera Changed Listener coordinates:
xx.xxxxxxxxxxxxxxx xx.xxxxxxxxxxxxxxx
Can anyone explain this?
I have to get the accelerometer values in time.
I saw the Sensor class and the SensorEventListener but this listener notify only when the value changes and I need a periodic notification (also if the value do not change).
Otherwise I would like to continuously read the accelerometer value but it is not possible according to this thread: Get current SensorEvent value
What can I do?
Why do you need to continuously "read" the sensor values even when they are the same as before? If you need to calculate some output on a regular basis, then a better solution might be to set up a timer that triggers on the required intervals at which time you use the values from a set of variables that are updated whenever the sensor values change. That way even if they don't change, the timer will initiate the calculations.
Kaamel
I have question about:
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, time, distance, locationListener);
I don't know how it's work, in this listener i have method onLocationChanged(Location location), but when listener call this method ? I have two variable, time in miliseconds and distance in meters, first variable tell when the location should be refresh, but we have second variable, and what ? Meybe it's working that, when the time(value from time variable) is gone, listener check distance between last postion and new position and if the distance between this positions is bigger than value from distance variable, listener will call onLocationChanged method. Right ? And i can use LocationListener for NETWORK_PROVIDER and for GPS_PROVIDER and it's works the same way. Right ? That this working ?
Time is your refresh interval i.e. location is refreshed by that amount of time. distance is the minimum change in distance in order to call onLocationChanged, basically these 2 parameters kinda filter the location you want. NETWORK and GPS provider more or less work same way, GPS is more accuracte but slow and network provider is less accurate and fast. You can check the accuracy on each location object though. So you are on the right track. Also check google play services location api which can be found here: https://developer.android.com/training/location/retrieve-current.html
I am using the new API V2, but that's probably not important since I am newbie for maps anyway:)
I have very simple need. I want to show my location and one target marker and all is working. It's just that the my location determination is not predictable, can get minutes or so to get the blue circle.
What I thought is to manually use the LocationManager to retreive in background the coarse or fine location and pass that value to the Mapactivity. Since normally the map activity will not start immediatelly it would work nice. Then I could also save to databse the last location and pass that in the case the map activity starts before the LocationManager get the real location.
I am looking at the api's but could not find a function that would display imemdiatelly the blue circle at given LatLong. Is this function available?
If this function is not available the only workaround that I could find is to override onlocationchanged to retrieve the new location and save the last, and to display the marker on last known mylocation (that would hide automatically itself on first locationchanged event).
But it would be easier, and also pretier, if I could simply pass initial mylocaltion coordiantes?
Thanks for any idea
I am looking at the api's but could not find a function that would display imemdiatelly the blue circle at given LatLong. Is this function available?
Use setLocationSource() to provide a LocationSource to the GoogleMap. Once your LocationSource is called with activate(), you will be handed a listener object, to which you can pass Location objects for the readings you get from a location provider.