JohnLM 14 Posted July 15, 2023 I have an e-scooter that I use for riding around towns and trails. There is an app to download. However, that app does not connect to my scooter and the developer is slow to fix/resolve/respond and still does not connect. So, I would like to look into writing my own app for my phone (android) to do the following: 1. track start and end times 3. track my routes - where i've been or stopped at 4. show the miles I am traveling during my ride in real-time 5. show the total miles of my ride 6. possibly show speed (via calculation) and in real-time 7. eventually, to show a map of my route in real-time, and show all my stops Is this possible with Delphi 11.2 and free components/services/API's ? Share this post Link to post
FPiette 382 Posted July 16, 2023 (edited) You showed the features you want your application have. Good. But what can you do and what can't you do? To answer to your exact question: Yes, it is possible to do it with Delphi 11.2 and free components/services/API's. Edited July 16, 2023 by FPiette 1 Share this post Link to post
David Heffernan 2345 Posted July 16, 2023 (edited) Buy a GPS watch. Or install strava on your phone. Edited July 16, 2023 by David Heffernan 1 Share this post Link to post
JohnLM 14 Posted July 17, 2023 After some searching, I found and tried various code snippets dating back a few years but they did not work because they were missing the code snippets for handling Permissions on Android or at least my phone's version of Android 12. Then, I decided to search around in my samples folder and did find a sample called, "Location" in the C:\Users\Public\Documents\Embarcadero\Studio\22.0\Samples\Object Pascal\Mobile Snippets\Location folder. I compiled it into my Android phone and it work right from the start. Thanks, Embarcadero! I also found a couple of youtube videos, below, showing exactly this app in action. I believe I can complete steps 1, 2, and 6, below. 1. track start and end times 2. track my routes - where I've been or stopped at 3. show the miles I am traveling during my ride in real-time 4. show the total miles of my ride 5. possibly show speed (via calculation) and in real-time 6. eventually, to show a map of my route in real-time, and show all my stops Share this post Link to post
FPiette 382 Posted July 17, 2023 For steps 3, 4 and 5, you need to compute the distance between two consecutive GPS coordinates. For that you use the "haversine distance". Here is some code I wrote for the purpose : // Return distance in meters between two points given by their // latitude/longitude expressed in degrees function HaversineDist( Lat1 : Extended; // Latitude of point 1 in degrees Lng1 : Extended; // Longitude of point 1 in degrees Lat2 : Extended; // Latitude of point 2 in degrees Lng2 : Extended) // Longitude of point 2 in degrees : Extended; // Distance in meters var Dx, Dy, Dz : Extended; const Diameter = 2 * 6372.8 * 1000; // Meters begin Lng1 := DegToRad(Lng1 - Lng2); Lat1 := DegToRad(Lat1); Lat2 := DegToRad(Lat2); Dz := Sin(Lat1) - Sin(Lat2); Dx := Cos(Lng1) * Cos(Lat1) - Cos(Lat2); Dy := Sin(Lng1) * Cos(Lat1); Result := ArcSin(Sqrt(sqr(Dx) + Sqr(Dy) + Sqr(Dz)) / 2) * Diameter; end; Once you get the distance between consecutive GPS points, you can sum the distances to get the track length. To get the speed, you divide the distance by time, you get m/s that you can easily convert to the units you like. Share this post Link to post
FabDev 8 Posted July 19, 2023 Hello, I recommand this very powerful component : TecNativeMap component Share this post Link to post
FPiette 382 Posted July 19, 2023 When buying third party component be sure to buy with FULL source code. And when you receive it, first thing to do is discard any dcu, bpl, obj, dll and all other binary files and rebuild everything. That way you are sure to have full source code an use that code. Why? Because one day or another the developer will disappear or stop updating his code for next Delphi release. With full source code, you can simply [most of the time] rebuild the product with the next Delphi version. 2 Share this post Link to post
David Schwartz 426 Posted July 19, 2023 Check out what TMS Software has -- they have been going nuts adding features to their mapping components. Share this post Link to post
JohnLM 14 Posted July 21, 2023 For step 2, I've added a tmemo control to hold all the data (latitude and longitude) that comes in during my travels. In addition, I added to the list to include an Index counter (line # 1, 2, 3, .. 200, etc.) and a time stamp entry for each lat/long value, thus. . . 001 - 5:06:03 PM - 0.0101-nnn : 0.0101-nnn 002 - 5:06:09 PM - 0.0102-nnn : 0.0102-nnn 003 - 5:06:10 PM - 0.0102-nnn : 0.0103-nnn I just need to find a way to plug those values for the lat/long into a map somehow and have it plot my previous travel route onto a map in my app. Next, I will research how to do this. Share this post Link to post
Dave Nottage 557 Posted July 21, 2023 14 minutes ago, JohnLM said: I just need to find a way to plug those values for the lat/long into a map somehow and have it plot my previous travel route onto a map in my app. There's a demo on using TMapView and placing markers, here. Share this post Link to post
FPiette 382 Posted July 22, 2023 7 hours ago, JohnLM said: I just need to find a way to plug those values for the lat/long into a map somehow and have it plot my previous travel route onto a map in my app. You can use the free OpenStreetMap topographic maps and use their "tile server" to download the tiles. Those are simple JPG images of the map at different zoom factor. Look there : https://wiki.openstreetmap.org/wiki/Tiles. URL := Format('https://tile.openstreetmap.org/%d/%d/%d.png', [Zoom, TileX, TileY]); FSslHttpCli.URL := URL; FSslHttpCli.OnRequestDone := SslHttpCliRequestDone; FSslHttpCli.RcvdStream := TMemoryStream.Create; FSslHttpCli.GetASync; Share this post Link to post
Rollo62 536 Posted July 25, 2023 Although this should be possible with Rx11.2, you should be aware that you are touching quite a lot of critical Android stuff, which needs each a lot of experience and knowledge, like - sensors and location - permission handling - I assume you would like to have background operation - therefor you would need Android services very likely I am not sure, if you start with a new project with Rx11.2 on Android for the first time. That's why I think this maybe quite a big task to get a smooth and easy start. Better try and test each of those problem zones separately, instead of putting it all together in the first try. Share this post Link to post
JohnLM 14 Posted July 25, 2023 @ Rollo62, Hi, I am starting out slowly. But I've coded various apps on Android over the years since XE7. I am not fluent in the Permissions area, but so far in this project, I am okay with what I have working on. I ride through trails in my area, so I am using that as an opportunity to test my app in order to debug and make any necessary changes/additions. 1 Share this post Link to post