Android getSpeed from location - android

I'm creating an application that gets the users speed whilst driving using the Android Location class. The problem that I am facing is that every post on a forum or article explains problems with the getSpeed() method. Having just gone into my car to test several times, it returns 0. I am not sure why, just wondering if anyone has been able to find out why and how to get the actual speed?
Thanks in advance

getSpeed works just fine, provided you have a capable GPS hardware in your device and you have enough satellites in sight. I am using it for a flight logging application.
One issue with getSpeed is, that the emulator will always return 0; even if it is fed with NMEA data which has speed info. So testing requires the real devices.
If the GPS receiver is inside the car, one issue might be, that it cannot acquire enough satellites in time for your test. Try leaving the device near the windshield (if it is not covered with a reflective surface based on something metallic!) and give it time to get a fix. Consider using a GpsStatusListener to get a count of visible satellites.
The trick mentioned above to compute speed from distances of samples requires filtering of the data. The more samples you use the more noise you get (which needs filtering, search for it here, there are several articles on stackoverflow on this topic). The less samples you use the greater is the error when not moving on a straight line.

Related

I'm getting very low accuracy from getCurrentPositionAsync(), sometimes more than 2000m. How could I improve this?

I’m working on an app that needs to save user's current position. The user is not really moving much, think fishing or birdwatching... they'd approach the spot and they stay there for a while, take a photo and then move to another location relatively close by.
For context, I'm using React Native/Expo (managed), so the relevant code goes like this:
let coordinates = await Location.getCurrentPositionAsync({
enableHighAccuracy: true,
accuracy: Location.Accuracy.Highest,
})
Then if resulting accuracy is greater than 50m I repeat the request.
This seems to work fine in urban or semi-urban areas where I guess there's a lot more info for the device to work with (WiFi networks, good mobile connection, cell towers, etc.). But in many cases there's very low mobile signal or none at all. Just GPS. In these situations, results get very inconsistent. Sometimes accuracy goes up to 2000 and 4000 meters which is useless for our purposes.
I think I must be using the wrong approach b/c there's tons of apps that work way better in similar situations, right?
Should I try to collecting positions of the device leading to the final place where the position will be recorded? Could that help without snapping to roads?
I’ve read an article from another app suggesting their users that in some cases historical GPS data is used and sometimes it helps getting rid of that data before attempting to get current position. Does this make sense to try? Is there ways to clear this data in the Expo/RN context?
We've tested this in different areas, in 3 or 4 Android devices, models ranging from about 1 to 4 years old. The data seems to indicate worse accuracy in older models, but still I thought GPS with clear sky view would do better...
I'd appreciate any suggestions or pointers to any relevant info. I'm sure there must be something we're doing very wrong.
Thanks.

Android Location "going for a walk" by itself

I am working on the GPS part of a project and I would like to get something past the community. I have searched around for all the typical GPS "jumping and drifting" and I have worked on improving what I get but last week I got some really weird data that I cannot put my finger on.
The application basically has a foreground service that tracks the location and then uploads that data on a timer. Of course we have all the proper permissions needed and there is also a filter that weeds out data with really bad accuracy and "detects" stops. All was working well until what you can see here happened.
These are some of the data points I got. A "beautiful" pattern drawing. The same happens to another location too but not to this extend. I checked the data to find out why my filter didn't even try to make things better and I found out that it would be unable to. All the points have proper speed, heading, and accuracy and for all intents and purposes I could say that the person actually did the whole thing. The problem is that it didn't happen. The phone, (Samsung J5) might not be the best there is out there, was in a room the whole time. From my understanding of the Fused Location Provider there is no speed reported if there is no GPS involved in the process. And lets assume that where the phone was sitting it could actually get a GPS signal. I can see it jumping around but going for a walk around the neighborhood?
I know and understand that the location in Android (and any other platform) can be a very complicated matter comprised of many different variables that mainly start from the hardware providing these variables, but how can we explain this sudden influx of crazy, even though seemingly proper, data? Can we consider that keeping the location service up and running for a long time actually bogged or "tired" the system? How can the same device that has given OK data to this point suddenly provide this dataset?
To add to the issue. In the data there were also one or two long delays of around 2 minutes (intervals set to 15 and 10 (for fastest) seconds). I am 100% sure that the service did not restart or anything of the kind because I am logging for that.
Any kind of insight would be greatly appreciated and if there is any way/method/algorithm you could recommend looking into to "fix" this kind of behavior would be great. Thank you in advance and sorry for the long question. I needed to provide a proper background.
EDIT: This is not really the answer to my question, why such a behavior suddenly appears, so I am adding it here as a way to try and mitigate the problem, at least a bit. I decided to use the Google's ActivityRecognitionAPI (comes bundled in the location API so no need to have more dependencies) and merged its output with my existing filter to hopefully "fix" the "false" location data.
If someone could still, though, give me a good answer (help me understand) on whether there are factors like long running times, or other hardware (or software) factors (excluding the typical knowledge that GPS chips on phones are bad) that can cause weird and unexpected behaviors like the mentioned one would be rather appreciated.
(We can of course always say - "It is the phones fault" - and be done ;) )
The GPS has errors, so even if you stand still at the same point you will get different readings. There's a couple of things you can do:
Use the accuracy value of the GPS - if the distance between the new reading and the previous one is lower than the accuracy - ignore it.
Use the device's accelerometer in order to determine if it's moving or not.

How accurate is the getSpeed() [duplicate]

I've been doing a bit of research on a problem we are trying to solve. I think this is the best approach but please add in your opinions
We are trying to calculate reaction times in a real world driving scenario and would like to use a mobile phone as the data collection device. What we are trying to accomplish is how much acceleration and more importantly deceleration a driver exerts when exposed to certain prompts.
I found this paper that has allot of useful information Accelerometer physics
The problem is that we most likely will not have a calibration time to start at zero.. however it is assumed that the driver is starting at 0. We will use GPS positioning to locate the vehicle, tracking the time stamped location data we should calculate the time when the prompt took place then using the time stamped accelerometer data we should be able to calculate their reaction to the prompt.
This is the best way I have found to solve the problem however I'm not sure if the accelerometer data will be rendered useless because of not being able to calibrate it and also the noise seen from vibrations may be too great to use the data... Has anyone tried or used these types of methods before?
Interesting application.
You are missing an important point. You either have to implement the so-called sensor fusion yourself or use the sensor fusion provided on the platform you are using. Both Android and iPhone have one.
The TYPE_LINEAR_ACCELERATION (Android, SensorManager) or userAcceleration (iPhone) should be sufficient for you.
As for the linked PDF, don't try integrating the acceleration, you will get very poor results. Even though that answer is about position, the velocity will already be inaccurate. I would try the GPS instead.
I know it's very old question but since I am recently working on a similar project let me share what we did in our company. We simply used OBD-II dongle to get velocity of car. There are many API's that return information about vehicle.
PID010D returns speed of vehicle. I'm using this PID to calculate distance between points A and B since there is no PID to return Odometer :(
There are few libraries on github that you can find easily by search. This mine. This is not library but after run on your device you can see how it works.

Using accelerometer to calculate speeds

I've been doing a bit of research on a problem we are trying to solve. I think this is the best approach but please add in your opinions
We are trying to calculate reaction times in a real world driving scenario and would like to use a mobile phone as the data collection device. What we are trying to accomplish is how much acceleration and more importantly deceleration a driver exerts when exposed to certain prompts.
I found this paper that has allot of useful information Accelerometer physics
The problem is that we most likely will not have a calibration time to start at zero.. however it is assumed that the driver is starting at 0. We will use GPS positioning to locate the vehicle, tracking the time stamped location data we should calculate the time when the prompt took place then using the time stamped accelerometer data we should be able to calculate their reaction to the prompt.
This is the best way I have found to solve the problem however I'm not sure if the accelerometer data will be rendered useless because of not being able to calibrate it and also the noise seen from vibrations may be too great to use the data... Has anyone tried or used these types of methods before?
Interesting application.
You are missing an important point. You either have to implement the so-called sensor fusion yourself or use the sensor fusion provided on the platform you are using. Both Android and iPhone have one.
The TYPE_LINEAR_ACCELERATION (Android, SensorManager) or userAcceleration (iPhone) should be sufficient for you.
As for the linked PDF, don't try integrating the acceleration, you will get very poor results. Even though that answer is about position, the velocity will already be inaccurate. I would try the GPS instead.
I know it's very old question but since I am recently working on a similar project let me share what we did in our company. We simply used OBD-II dongle to get velocity of car. There are many API's that return information about vehicle.
PID010D returns speed of vehicle. I'm using this PID to calculate distance between points A and B since there is no PID to return Odometer :(
There are few libraries on github that you can find easily by search. This mine. This is not library but after run on your device you can see how it works.

is there a better alternative to gps position tracking?

After doing some asking around and reading, it sounds like you're lucky to get even within 10 meters of accuracy with a GPS on a mobile device (specifically Android).
I've seen a video that shows a home-made device reading out to several decimals. Is this only because of the data format from the chip? (aka, not really precise either?)
Is there any real working way that I can use an Android device to track real static positions within rooms in a building?
Ideally, I'd be able to mark a point in a room and come back to it later with virtually no drift.
The LocationProvider is different from each Android Device you are using. The SDK does not handle the calculation of your exact location but the phone does. But each device can have one or mare LocationProvider, thats why you need to set some Criterias when your picking a LocationProvider.
To get your exact position on the earth the GPS needs 3 points from 3 different satellites. Thats why the GPS works best in the open space. Regarding making a precise calculation on a static persion inside a building, this conflict with the whole scenario of the GPS-System. I'm not saying it's impossible to get a location inside a building but as with any other signals, obstacles that blocks the signal makes is weaker.
If you are inside a barn with thin walls this might work, but inside a 10 storage building your scenario seems quite impossible.
You can though force your phone to get the best LocationProvider and hopefully that will give you the most precise location. And yes, you can get inside 1-2m in precision outside.
I hope this helps a little. Enjoy your project.

Categories

Resources