The MapPoint class defines geographic points (longitude, latitude) and methods to work with geographic points in the 'World Geodetic System 1984' (WGS84 or EPSG:4326).
If you have never worked with geographic coordinates before, a look at these web pages will help:
The following initial values have been successfully tested in the Gambas projects:
The MapPoint class has these properties:
Property | Data type | Description |
---|---|---|
Lat | Float° | Returns the latitude of a map point (MapPoint) as a decimal degree value. |
Lon | Float° | Returns the geographical longitude of a MapPoint as a decimal degree value. |
Table 24.8.3.2.1 : Properties of the class MapPoint
The MapPoint(Latitude As Float, Longitude As Float) As MapPoint function initialises a map object with a geographic starting point (latitude°, longitude°):
Dim myMapPoint As MapPoint = MapPoint(52.78631, 11.73872) ' Ort Osterburg
24.8.3.3 MethodsThe MapPoint class has the following three methods:
method | return type | description |
---|---|---|
Distance ( PointA As MapPoint, PointB As MapPoint ) | Float | The function calculates the (direct) distance (distance in metres!) between two geographical points, of which the latitude and longitude are known as decimal degree values. |
Bearing(From As MapPoint, To As MapPoint) | Float | Calculates the (starting) bearing in degrees between two geographical points, of which the latitude and longitude are known as decimal degree values. |
From(MapPoint as MapPoint, Bearing As Float, Distance As Float) | MapPoint | Calculates the target point B from a starting point A, a bearing (in degrees) and a distance (in metres). In this sense From() is inverse to Distance() and Bearing(). |
Table 24.8.3.3.1 : Methods of the class MapPoint
The example refers to the calculations of the distance and the starting bearing for the two cities Osterburg and Berlin:
Dim mpOsterburg, mpBerlin As MapPoint mpOsterburg = New MapPoint(52.78631, 11.73872) mpBerlin = New MapPoint(52.516250, 13.378870) Print "Geografische Breite 'Osterburg' = "; mpOsterburg.Lat; "°" Print "Geografische Länge 'Osterburg' = "; mpOsterburg.Lon; "°" Print "Entfernung Osterburg-Berlin = "; Round(Distance(mpOsterburg, mpBerlin) / 1000, -3); " km" Print "Start-Peilung = "; Round(Bearing(mpOsterburg, mpBerlin), -3); "°"
Output in thee console of the IDE:
Geografische Breite 'Osterburg' = 52,78631° Geografische Länge 'Osterburg' = 11,73872° Entfernung Osterburg-Berlin = 114,994 km Start-Peilung = 104,532°
Figure 24.8.3.4.1: Distance Osterburg - Berlin (as the crow flies)
The console program geod also gives very good results, as it - like the component gb.map - uses the model WGS84-Ellipsoid for calculation. It is quickly installed:
hans@linux:~$ sudo apt-get install proj-bin
and with the following call and the geographical coordinates to be entered afterwards for two places (Osterburg and Berlin (Mitte)) it delivers adequate results (indication of the distance in kilometres) like the MapPoint.Distance method:
hans@linux:~$ geod +ellps=WGS84 +units=km -I 52.78631 11.73872 52.516250 13.378870 104d29'46.077" -74d11'59.931" 114.994