Search code examples
qmlqt5

Geocode Model not updating on button click


Im having an issue getting my GeocodeModel to translate addresses into coordinates and then send it on to the RouteModel. Heres what I think is the relevant code:

Address {
    id: fromAddress
    street: "2193 Lake Louisa Rd"
    city: "Hiawassee"
    country: "United States"
    state: "Georgia"
    postalCode: "30546"
}

Address {
    id: toAddress
    street: "205 N Berrong St"
    city: "Hiawassee"
    country: "United States"
    state: "Georgia"
    postalCode: "30546"
}
...
Button {
    id: testButton2
    text: "route test"
    onClicked: {
        geocodeModel.startCoordinate = QtPositioning.coordinate()
        geocodeModel.endCoordinate = QtPositioning.coordinate()
        geocodeModel.query = fromAddress
        geocodeModel.update();
    }
    anchors.left: testButton1.right
}

GeocodeModel {
    id: geocodeModel
    plugin: mapPlugin

    property int success: 0
    property variant startCoordinate
    property variant endCoordinate

    onCountChanged: {
        if (success == 1 && count == 1) {
            query = toAddress
            update();
        }
    }

    onStatusChanged: {
        if ((status == GeocodeModel.Ready) && (count == 1)) {
            success++
            if (success == 1) {
                startCoordinate.latitude = get(0).coordinate.latitude
                startCoordinate.longitude = get(0).coordinate.longitude
                console.log("We applied the start coords")
            }
            if (success == 2) {
                endCoordinate.latitude = get(0).coordinate.latitude
                endCoordinate.longitude = get(0).coordinate.longitude
                console.log("We applied the end coords")
                success = 0
            if (startCoordinate.isValid && endCoordinate.isValid)
                setRoute(startCoordinate,endCoordinate)

            }
        }

        else if ((status == GeocodeModel.Ready) || (status == GeocodeModel.Error))
            if (status == GeocodeModel.Ready && (count == 0)) {
                console.log("Unsuccessful geocode");
            }
            else if (status == GeocodeModel.Error) {
                console.log("Geocode Error");
            }
            else if (status == GeocodeModel.Ready && (count > 1)) {
                console.log("Ambiguous geocode");
            }

            navMap.geocodeFinished()
    }
    onLocationsChanged: {
        if (count > 0) {
            navMap.center.latitude = get(0).coordinate.latitude
            navMap.center.longitude = get(0).coordinate.longitude
        }
    }
}

When I run this all I get back is "Unsuccessful geocode" acting like it never loaded in my addresses into the Model. I dont even hit my success console.logs. Im at a loss


Solution

  • In the end Jurgen was right, it ended up being an issue with osm parsing the address