Android Question How to draw a GPS Route WHITOUT a maps app

ivan.tellez

Active Member
Licensed User
Longtime User
I´m looking at measuring some small routes using GPS, the longest one is like 650 meters, this routes can have several corners. The idea is to have the GPS on and walk the path, click a button on each corner and calc the distances beetween those points. This is already working.

Has anyone drawn GPS data on a canvas? Is there a library or some example code to draw the route scaled to use all the canvas.

Concept:

1664819012168.png


Thanks
 
Solution
Anyway, for the original question. It makes no sense at all the convertion to meters. The steps are:

1. Find the bounding box. (the smallest Lat and smallest Lon in the list, the largest Lat and largest Lon in ther list).
2. Find a scaling factor to avoid distorting the image so we calculate the scaling factor for the x coordinate and the y coordinate:

B4X:
ScalingFactorX = Canvas.Width / (MaximumLat - MinLat)
ScalingFactorY = Canvas.Height / (MinLon - MinLon)
ScalingToUse As Double = Min(ScalingX, ScalingY)

For longer distances or for northern/soutern locations you can use cos(latitude) as an extra Scalingfactor

3. For Each location, get the X and Y

B4X:
        Dim X As Int = (Location.Latitude-MinLat) * ScalingToUse...

ivan.tellez

Active Member
Licensed User
Longtime User
I would like to see the result of your solution.

1665200375403.png


Green line moves as you walk, all the lines are drawn in the same rect so it "zooms" as you move. It works now, Needs a little work on positioning labels, better graphics and maybe later some interaction.

Each location point can be added only if the GPS accuracy is <= 5
 
Last edited:
Upvote 0

ivan.tellez

Active Member
Licensed User
Longtime User
converting degrees to meters makes more sense
ROFL, using an aproximation to convert degrees to meters and then meters to pixes with all the loss of accuracy that implies is plain dumb.

Why bother adding an unnecessary middle conversation that adds more code, more operations and less accuracy if you can plot degrees directly? ?
 
Upvote 0

emexes

Expert
Licensed User
ROFL, using an aproximation to convert degrees to meters and then meters to pixes with all the loss of accuracy that implies is plain dumb.

Java math usually defaults to Double, so as long as you don't store any intermediate results as Floats, you'll be ok, per my explicit mention of:
+++ best use Double; single precision Float is probably not precise enough

Why bother adding an unnecessary middle conversation that adds more code, more operations and less accuracy if you can plot degrees directly? ?

Because then the aspect ratio is wrong.

Latitude degrees are longer than longitude degrees.^ In Spain around latitude 42°, longer by about a third.

But if you're not worried about equal horizontal and vertical movement being displayed as equal-length lines, then: sure, you can skip that adjustment. ?

But you just referred to "loss of accuracy", so presumably an out-by-one-third issue is of interest to you.


^ unless you are sitting within about 3.3° of the equator, thanks to the earth being oblate
 
Last edited:
Upvote 0

ivan.tellez

Active Member
Licensed User
Longtime User
Latitude degrees are longer than longitude degrees.^ In Spain around latitude 42°, longer by about a third.

But if you're not worried about equal horizontal and vertical movement being displayed as equal-length lines, then: sure, you can skip that adjustment. ?

Still not needed any Km conversion. It is just a simple cos(latitude) to get the scaling factor.
 
Upvote 0

emexes

Expert
Licensed User
Still not needed any Km conversion. It is just a simple cos(latitude) to get the scaling factor.

Now that you've added that longitudinal adjustment to your solution, I agree. Not sure why you didn't fix the other two issues while you were there.

Originally you were looking for a non-pure-math solution, so I kept things easy and step by step. And you were calculating distances in meters (presumably using Location.DistanceTo) and it was just as easy to have the equal-scale intermediate cartesian coordinates in meters as in degrees of 60 nautical miles. Whatever unit suits your purpose best, use that. I don't mind. Although I do agree with:

Still not needed any Km conversion.

because using kelvin-meters for distance is just going to confuse us both. ?
 
Upvote 0

Sailboat11

Member
Licensed User
The way that I track anything is with Lat/Long coordinates. I parse the results to fit on the screen. I use minutes if I'm tracking cars or airplanes or anything else that going to cover miles. I need to use seconds if I'm tracking people or sailboats or something that's moving over small distances. An application can use a generic substitute for degrees and minutes if you are using a small area and only use seconds for an application that works just about anywhere. Using some heavy math between hits of "LocationChanged(Location1 As Location)" will give you all the accuracy most people need for distance.
 

Attachments

  • a51.png
    32.1 KB · Views: 156
Upvote 0

Sailboat11

Member
Licensed User
Location.DistanceTo in smaller walking applications using seconds isn't very accurate. The course part of the GPS library works well to identify turns or changes in direction. There are some good examples of heavy math on the forum. They give consistent reliable results. The graphic below uses Location.DistanceTo and has good accuracy because of its size. The red line is a finger swipe giving the user the distance of the red line. Everyone needs to know how many miles until they get to their next location or stop.a20 (1).PNG
 
Upvote 0

emexes

Expert
Licensed User
Location.DistanceTo in smaller walking applications using seconds isn't very accurate.

I can vouch for it working great in the southern hemisphere, albeit that is mostly whilst driving.

Do you have an example of two (lat, lon) points where Location.DistanceTo "isn't very accurate" compared to heavy math?
 
Upvote 0

Sailboat11

Member
Licensed User
I think the lack of distance accuracy is due to scale. Using DistanceTo in the GPS Library works great for driving and in almost all programs like that use the "minutes" function. When we want feet or yards or maybe even meters, and the scale is small, we use the "seconds" function of the GPS Library. I have measured 94 feet from the back door to the shop. Also, it appears that some supermarkets have WiFi with GPS. My walking program works inside my food store. There may be some business opportunities for programmers using this technology.

To answer some other questions. Yes, you can draw track lines on a canvas. You can use a map or not. Fitting a map to the screen takes some time when you change devices. The map has to be scaled to the device. I'm doing it the same way I did it using Java Script and Pearl. I guess I'm old school. Code sippets are available on request. Whole programs are big and not very portable.
 
Upvote 0
Top