User Tools

Site Tools


Sidebar

Network and communication

k24:k24.8:k24.8.3:start

24.8.3 MapPoint

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:

24.8.3.1 Geographical Coordinates

  • The geographical coordinates of a location on the fictitious Earth sphere are the latitude and the longitude.
  • The latitude and longitude are angular values. Angles are given either in decimal notation or in sexagesimal notation (base 60), where 1 degree has 60 (arc) minutes and 1 minute has 60 (arc) seconds.
  • The coordinate origin for latitude is the equator. Latitude thus takes values of -90° < latitude ⇐ +90° or 90°S < latitude ⇐ +90°N. Special features are described very clearly in an article at http://en.wikipedia.org/wiki/Mercator_projection.
  • The coordinate origin for the geographical longitude is the zero meridian. The longitude thus takes values of -180° < longitude ≤ +180° or 180°W < longitude ≤ 180°E.

The following initial values have been successfully tested in the Gambas projects:

  • World Map Latitude = 8°, Longitude = -8° and Zoom = 1.
  • Germany Latitude = 51.4°, Longitude = 10.7° and Zoom = 6
  • Osterburg Latitude = 52.78979°, Longitude = 11.75280° and Zoom = 13

24.8.3.2 Properties

The MapPoint class has these properties:

PropertyData typeDescription
LatFloat°Returns the latitude of a map point (MapPoint) as a decimal degree value.
LonFloat°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:

methodreturn typedescription
Distance ( PointA As MapPoint, PointB As MapPoint )FloatThe 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)FloatCalculates 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)MapPointCalculates 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

24.8.3.4 Example

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°

Distance
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
The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k24/k24.8/k24.8.3/start.txt · Last modified: 16.08.2022 (external edit)

Page Tools