0

I am using the ArcGIS QT/C++ api and I found that when I grab the lat/lng from my cursor position (or just any point for that matter) is about 10 to 20 meters off. I think I might be missing a SpacialReference somewhere,... I just don't know where. I am using the qt100.12 runtime sdk.

Can anyone maybe give me a hint?

QPointF MapView::latLongAtCursor(){
    Esri::ArcGISRuntime::Point point = _mapView->screenToLocation(cursor().pos().x(), cursor().pos().y());
    QString raw_coords = Esri::ArcGISRuntime::CoordinateFormatter::toLatitudeLongitude(
        point,
        Esri::ArcGISRuntime::LatitudeLongitudeFormat::DecimalDegrees, 
        6
    );
    QStringList exploded = raw_coords.split(' ');
    QString first = exploded.first();
    QString last = exploded.last();
    double latitude = exploded.first().remove(-1, 1).toDouble();
    double longitude = exploded.last().remove(-1, 1).toDouble();
    if(first.endsWith("S")){
        latitude = -abs(latitude);
    }
    if(last.endsWith("W")){
        longitude = -abs(longitude);
    }
    return QPointF(longitude, latitude);
}

*Edit/Update: It seems that the call to cursor() returns an invalid x/y position to start with. I am using DockWidgets and it seems the problem lies within Qt.

Flip Vernooij
  • 889
  • 6
  • 15

1 Answers1

0

Turns out that cursor().pos() returns the global position within your application, not the relative position within your widget, to be clear, it returns the same position as QCursor::pos().

In order to get the relative position to your widget, you need to use mapFromGlobal(QCursor::pos())

I managed to get the mapping much more precise now. At very high zoom levels it does still show a difference yet I don't think I will ever be zooming that far.

Flip Vernooij
  • 889
  • 6
  • 15