Home > Back-end >  How to use QGeoCoordinate in Qt C , especially the azimuthTo() and distanceTo() objects?
How to use QGeoCoordinate in Qt C , especially the azimuthTo() and distanceTo() objects?

Time:07-24

This is my code: After specifying two different coordinates (geo and geo2), how can I know the distance between them using distanceTo()

//enter code here
QGeoCoordinate geo;
geo.setLatitude(90);
geo.setLongitude(90);
QGeoCoordinate geo2;
geo2.setLatitude(53.213456);
geo2.setLongitude(-9.182547);

edit: I have read the documentation but still unable to figure out the right way.

CodePudding user response:

As per the documentation, it is a simple call of taking one of the two QGeoCoordinate objects and pass the other object to its member function.

So your code becomes:

QGeoCoordinate geo;
geo.setLatitude(90);
geo.setLongitude(90);
QGeoCoordinate geo2;
geo2.setLatitude(53.213456);
geo2.setLongitude(-9.182547);
qreal distanceInMeters = geo.distanceTo(geo2);
  •  Tags:  
  • c qt
  • Related