This seems like it should be simple enough, but I can't seem to get a clear example of how to calculate my speed using Android's Location Services.
All I want to do is calculate my speed based on my previous and current GPS position. getSpeed() doesn't work, because it needs to be set at some point using setSpeed().
So is there any sample code out there that I can run in Eclipse against my Android emulator running a GPX file, that will show me my pace in any measure (meters, feet, miles, etc., doesn't matter - I can always convert this to what I need).
Thanks in advance,
Alex
Do you just mean something like this? Gives you the speed in m/s.
oldLocation.distanceTo(newLocation) / (newLocation.getTime() - oldLocation.getTime())
getSpeed() doesn't work, because it needs to be set at some point using setSpeed().
(In case you are using an actual device -- ). No, the speed is determined by the GPS chipset and it should be more accurate than getting the distance and time between two consecutive locations. You do not need to setSpeed() . Call hasSpeed() to see if the speed is valid.
(In case you're not using an actual device)
I've had good success using the mock location provider where you can set the Location object you want with setSpeed() in meters/second
Here are some ways of doing this :
Mocking using NMEA
Mocking using code
Related
i'm looking for the best way to implement a road navigator that gets the velocity, distance between 2 points using the smartphones techniques.
through my searches i found 2 different tech. using either the accelerometer or android API (android.Location).
some opinions said that using accelerometer wont give me an accurate results because there will be so much noises as a bumpy roads, buildings...etc and calculations will be so complex.
on the other hand using the Android API (android.Location) means i should always be connected to the GPS, doesn't that affect on the battery?!! and as i found i can't open the GPS by myself i used always ask the user for a permission(so boring). and is there an limitation
So kindly help to take a decision, is it useful to be connected 24 hours on GPS in order to update the device location.. or to use the accelerometer??
You definitely should use GPS. The battery will be strained but you get much more accurate result. Sensor should be used only when GPS is not available and for a short distance.
Using GPS you can call location.hasSpeed() and if positive call location.getSpeed() together with getBearing() will give you the velocity.
I am trying find out the speed and altitude in android without using getspeed() and getAltitude() methods. If any one has any reference material or code snippet with respect to this,please share it so that it can be of some help to me.
Speed can be done by keeping track of location on subsequent updates, finding the distance between them, and dividing by the time difference. Altitude- good luck, you'd need signal strength info that I don't think you can get. You really don't want to do it.
I a trying to create an application that will be able to guide people in a city, with points of interest. For this, I need the better accuracy I get, in order not to place POI where there is nothing...
To do this I use droidAR (it gives me a radar, and I can place my POI thanks to their coordinates). But the accuracy is so bad I can't see how this can used.
For exemple, to determine if I a close to a POI, I calculate the distance between it and my GPS position. It can be that, with a 10 meters accuracy given by Android when I place the POI, it is then 80 meters away when I try to find it.
SO I looked forward to find another position systems, I found :
skyhook, which is supposed to give a more accurate position. With this, I took 1000 points and checked their distance to the last point, it is always moving and it was sometimes 300m away, so it seems even less precise. Maybe anyone could use it successfully ?
someone told me to use DCM algo (Direct Cosine Matrix), that can give me an accurate relative position (no problem for my use cases to do every positioninf relative to a start point). Some drones are using it, it could reach 1 meter accuracy. But I couldn't find any implementation or help with Android.
Did anyone succeed into using the android GPS with accuracy ?
Either your android phone has a bad GPS device, or more probably you are doing something wrong. you can set a POI in city aprox. 5m acuracy, sometimes 20m. that is sufficient. check it with another GPS app that allows setting a waypoint.
In your app you could concentrate on the 95% GPS accuracy. There is nothing better than GPS (espcecialla yon a mobile phone), the other methods you described are for short time assistance to GPS, but they will not work good for pedestrians, they are made for vehicles (vehicles move straight most of the times, they cannot change its direction so fast like a human does).
Your problem is not the GPS location accuracy, it is the augmented reality projection of droidAR.
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.
What is the easiest way to find out how fast the Android device is traveling?
Also, is there a way to register an intent for speed? Example: intent if the device goes more than 20 miles an hour.
The easiest way is to get the speed of the device is from the GPS, more specifically the time it takes to travel between 2 points. Luckily this is already done for you with the Location class: Location.getSpeed() which returns a float with the speed in m/s.
See the Android developer reference for more info
you can calculate speed precisely by multiplying acceleration to time it was applied for. this method is very sensitive so you will have to add some border check to filter shakes.