Recent

Author Topic: TMapViewer  (Read 82222 times)

VTwin

  • Hero Member
  • *****
  • Posts: 927
  • Former Turbo Pascal 3 user
Re: TMapViewer
« Reply #120 on: April 30, 2019, 12:39:41 am »
For symmetry:

Code: Pascal  [Select][+][-]
  1. { DistanceToLatLong
  2.   Given a point defined by (lat,long), a distance and compass bearing, return
  3.   the coordinate of the resulting destination point. Uses mean spherical earth
  4.   radius. Angles are in radians, distances in meters.
  5.   Ref: http://www.movable-type.co.uk/scripts/latlong.html }
  6. procedure DistanceToLatLong(const lat0, long0, dist, bearing: double;
  7.   var lat1, long1: double);
  8. var
  9.   R: double = 6371000.0; // earth radius in meters
  10.   d, x, y: double;
  11. begin
  12.   d := dist/R; // angular distance
  13.   lat1 := ArcSin(Sin(lat0) * Cos(d) + Cos(lat0) * Sin(d) * Cos(bearing));
  14.   x := Cos(d) - Sin(lat0) * Sin(lat1);
  15.   y := Sin(bearing) * Sin(d) * Cos(lat0);
  16.   long1 := long0 + ArcTan2(y, x);
  17. end;  
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0.8 (64 bit Cocoa, also fixes and trunk)
Ubuntu 18.04.3: Lazarus 2.0.8 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.8 (64 bit on VBox)

wp

  • Hero Member
  • *****
  • Posts: 7551
Re: TMapViewer
« Reply #121 on: May 01, 2019, 12:32:50 am »
Found some documentation for the HERE maps (https://developer.here.com/documentation/map-tile/topics/introduction.html) and managed to integrate some variants into the MapViewer. Note, however, that (free) registration is required at https://developer.here.com/. After registration you'll receive an APP_ID and an APP_CODE; open the ini file of the demo program (in its exe folder) and add a section with the corresponding information (replace ABC and xyz by the strings sent to you by HERE):

Code: [Select]
[HERE]
APP_ID=ABC
APP_CODE=xyz

When you run the demo program the next time the HERE maps will be included in the map provider drop down. Unfortunately, ATM, it seems that the parameters are not yet inserted correctly into the URL, and there are a lot of drawing artefacts.

Another issue is that I do not get the fphttpclient to accept the https url. Therefore, I used the synapse downloader in the demo for the moment.
« Last Edit: May 01, 2019, 12:43:16 am by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

sstvmaster

  • Full Member
  • ***
  • Posts: 167
Re: TMapViewer
« Reply #122 on: May 01, 2019, 12:33:43 pm »
Another issue is that I do not get the fphttpclient to accept the https url. Therefore, I used the synapse downloader in the demo for the moment.

Can you give me a short example, please? Is the issue with all urls, or only with the HERE url?
Windows 10 (64 bit)
Lazarus: 2.0.10 / Trunk x32

wp

  • Hero Member
  • *****
  • Posts: 7551
Re: TMapViewer
« Reply #123 on: May 01, 2019, 12:49:02 pm »
HERE url only. The fphttpclient downloader reports the error: 'Project MapViewer_Demo raised exception class 'ESocketError' with message: Host name resolution for "0.base.maps.api.here.com" failed"'; the Synapse downloader works correctly.

Playing again with these maps and having this error message in mind, I get the idea that maybe the "0" in "0.base.maps..." is not valid; I replaced the %serv% in the AddMapProvider call (in TMapViewerEngine.RegisterProviders) by a hard-coded "1", and now also the fphttpclient works correctly, and even the drawing artefacts due to missing tiles that I reported yesterday are gone. So, the remaining problem is: How to convince the component to not generate URLs with a leading "0".
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

sstvmaster

  • Full Member
  • ***
  • Posts: 167
Re: TMapViewer
« Reply #124 on: May 01, 2019, 12:54:50 pm »
« Last Edit: May 01, 2019, 12:59:04 pm by sstvmaster »
Windows 10 (64 bit)
Lazarus: 2.0.10 / Trunk x32

wp

  • Hero Member
  • *****
  • Posts: 7551
Re: TMapViewer
« Reply #125 on: May 01, 2019, 05:45:05 pm »
The function GetYahooSvr is constructed such as to create server numbers starting at 1 instead of 0. Putting this into the AddMapProvider for the HERE mapes calls gives error-free access to these maps (provided that the HERE credentials have been obtained and have been made known to the demo program).
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Alekos

  • New member
  • *
  • Posts: 7
    • http://www.iqsoft.gr
Re: TMapViewer
« Reply #126 on: May 11, 2019, 05:40:48 pm »
Hi anyone has an example of TGPSTrack ?
Cant find anything.
Thanks!!!

wp

  • Hero Member
  • *****
  • Posts: 7551
Re: TMapViewer
« Reply #127 on: May 12, 2019, 11:52:42 pm »
A GPSTrack is a list a GPSPoints. Therefore, in order to create a GPSTrack you must create GPSPoints first and then add them to the Points list of the GPSTrack. Finally you add the track to the GPSItems of the viewer; give it a unique number to identify the track.

I added an example to the demo program of the MapViewer; find the code in unit gpslistform. At first add some gps points to the Viewer (by right-clicking at the track points). Then click "GPS points..." and "Save points" to save the points to a simple track file (just a tab-delimited file). When you want to see the track later, click again "GPS points..." and then "Load track".

[EDIT]
Added a parser for GPX files. In the demo there is a new button "Load GPX file" from which you can select your own GPX files or those downloaded from the internet (e.g.: http://www.gpsvisualizer.com/examples/google_gpx.html); the mapviewer will then display track, route and waypoints. When I have more time I'll add some machinery to assign particular icons to way points, e.g. trail head, mountain peak, etc.
« Last Edit: May 16, 2019, 12:12:28 am by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

JosepB

  • Newbie
  • Posts: 4
Re: TMapViewer
« Reply #128 on: June 10, 2019, 05:43:44 pm »
Thank you very much for the component, it works very well and every day is more complete. However, I wanted to make a suggestion to the developer, wp: would it be useful to add to the TGPSObj object a property with the IdOwner value in order to easily differentiate the different created and existing objects on the map ?.

wp

  • Hero Member
  • *****
  • Posts: 7551
Re: TMapViewer
« Reply #129 on: June 13, 2019, 12:13:54 am »
I made GpsObj.IdOwner public now. Is that ok for your needs?
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

JosepB

  • Newbie
  • Posts: 4
Re: TMapViewer
« Reply #130 on: June 13, 2019, 12:11:27 pm »
Thank you!.

immoblecher

  • New member
  • *
  • Posts: 5
Re: TMapViewer
« Reply #131 on: May 15, 2020, 11:06:31 am »
This is a very useful component and I could only try it out now. :( I even got it right to display points in different colours depending on the ELE value. But what I could not get right is to display the NAME as a label. I saw in the examples that there were some attempts with the ADrawer TextOut and TextExtent functions/procedures but they are not working and I guess therefore commented out. Trying to use them crash the application with lots of Access Violations. Anyone any other ideas on how one could display the labels? @wp: are you still working on that? That would be the jewel in the crown. ;)

winni

  • Hero Member
  • *****
  • Posts: 1813
Re: TMapViewer
« Reply #132 on: May 15, 2020, 12:53:14 pm »
For symmetry:

Code: Pascal  [Select][+][-]
  1.  
  2. procedure DistanceToLatLong(const lat0, long0, dist, bearing: double;
  3.   var lat1, long1: double);
  4. var
  5.   R: double = 6371000.0; // earth radius in meters
  6.   d, x, y: double;
  7. begin
  8.   d := dist/R; // angular distance
  9.   lat1 := ArcSin(Sin(lat0) * Cos(d) + Cos(lat0) * Sin(d) * Cos(bearing));
  10.   x := Cos(d) - Sin(lat0) * Sin(lat1);
  11.   y := Sin(bearing) * Sin(d) * Cos(lat0);
  12.   long1 := long0 + ArcTan2(y, x);
  13. end;  

Hi!

This needs some speedup - there are situations where it is heavily used.

* Some values are computed twice with sin or cos -
  you can compute theses variables first
* To speedup you can do math.sincos where sinus and cosinus are
  computed in one job.
* We should take the latest exact value for the earth radius from WGS84 = 6378137.0 meters

Code: Pascal  [Select][+][-]
  1. procedure DistanceToLatLong(const lat0, long0, dist, bearing: double;
  2.                                              var lat1, long1: double);
  3.  
  4. var
  5.   //R: double = 6371000.0; // earth radius in meters
  6.   R : double =  6378137.0; // WGS84
  7.   d, x, y: double;
  8.   cosd, sind, coslat0, sinlat0 : double;
  9. begin
  10.   d := dist/R; // angular distance
  11.   math.sincos (d,sind,cosd);
  12.   math.sincos (lat0,sinlat0, coslat0);
  13.   lat1 := ArcSin(sinlat0 * cosd + coslat0 * sind * cos(bearing) );
  14.   //lat1 := ArcSin(Sin(lat0) * Cos(d) + Cos(lat0) * Sin(d) * Cos(bearing));
  15.   x := cosd - sinlat0 * sin(lat1);
  16.   //x := Cos(d) - Sin(lat0) * Sin(lat1);
  17.   y := sin(bearing) * sind * coslat0;
  18.   //y := Sin(bearing) * Sin(d) * Cos(lat0);
  19.   long1 := long0 + ArcTan2(y, x);
  20. end;                                  
  21.  

And don't forget:

The earth is an ellipsoid - at the poles the radius is about 21 km less than at the equator.
(So it's easierer for the Trolls from Midearth to the surface ....)

This can lead to 0.5% deviation.

Winni

wp

  • Hero Member
  • *****
  • Posts: 7551
Re: TMapViewer
« Reply #133 on: May 15, 2020, 01:32:13 pm »
The earth is an ellipsoid - at the poles the radius is about 21 km less than at the equator.
... This can lead to 0.5% deviation.
So then, why do you care about the difference between 6371000 and 6378137 when you do not use the exact formula for an ellipsoid? And even worse, as wikipedia shows (https://en.wikipedia.org/wiki/Earth_radius#Published_values), the former value is almost exactly the radius of the "average" sphere (having the same volume as the ellipsoid) while your value is the radius at the equator (major axis). Using this will overestimate all distances (except for those near the equator) while the former one leads to a more evenly distributed error.

There is one more optimization: since lat1 is the arcsin of some expression it is not necessary to calculate sin(lat1) because that is just the value of that expression put into the arcsin as argument.
Code: Pascal  [Select][+][-]
  1. procedure DistanceToLatLong(const lat0, long0, dist, bearing: double; var lat1, long1: double);
  2.  
  3. var
  4.   R: double = 6371000.0; // earth radius in meters
  5.   d, x, y: double;
  6.   cosd, sind, coslat0, sinlat0, sinlat1: double;
  7. begin
  8.   d := dist/R; // angular distance
  9.   math.sincos (d,sind,cosd);
  10.   math.sincos (lat0,sinlat0, coslat0);
  11.   sinlat1 := sinlat0 * cosd + coslat0 * sind * cos(bearing);
  12.   x := cosd - sinlat0 * sinlat1;
  13.   y := sin(bearing) * sind * coslat0;
  14.   lat1 := ArcSin(sinlat1);
  15.   long1 := long0 + ArcTan2(y, x);
  16. end;

But: I just wanted to update the source, but there is no DistanceToLatLong() anywhere within LazMapviewer. So, what are you talking about?
« Last Edit: May 15, 2020, 01:38:49 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

winni

  • Hero Member
  • *****
  • Posts: 1813
Re: TMapViewer
« Reply #134 on: May 15, 2020, 02:02:07 pm »
@wp

I'm talking about VTwins posting.
Sometimes reading helps.

About the earth radius:

The international astronomical SI unit is
6.3781×10^6 m

In geophysics the mean radius is defined as
 6.371.0088 m

And Erastothenes computed around 200 BC a value of
6.645 km
- not bad.

Winni

 

TinyPortal © 2005-2018