C
Qt Quick Ultralite map example
// Copyright (C) 2025 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial #include <qul/routeservice.h> #include <qul/georoute.h> #include <qul/application.h> #include "routeservice.h" double distance = 950; int travelTime = 590; const Qul::RouteServiceInterface::Path polyline = {{65.05877, 25.45545}, {65.05877, 25.455120588235296}, {65.05871352941178, 25.455015294117647}, {65.0582, 25.45502}, {65.05816, 25.45653}, {65.05805, 25.45771}, {65.05802, 25.45852}, {65.05652, 25.45852}, {65.05609, 25.458}, {65.05602529411765, 25.457969803921568}, {65.05594882352942, 25.45793411764706}, {65.05558, 25.45797}, {65.05524, 25.45833}, {65.05521666666667, 25.458338235294118}, {65.05507, 25.45839}, {65.05507, 25.45788}, {65.05471450980392, 25.458216274509805}, {65.0547, 25.45823}, {65.0544, 25.45649}, {65.05431352941177, 25.456576470588235}, {65.05427, 25.45636}}; void MyRouteService::onEvent(const DataReceivedEvent &event) { QUL_UNUSED(event); // Here would be platform specific code to fetch route data. // There are 2 potential scenarios: // 1. data was successfully received. // Store it into the distance, travelTime and path of GeoRoute object. static Qul::RouteServiceInterface::GeoRoute route; route.setDistance(distance); route.setTravelTime(travelTime); route.setPath(polyline); // call Qul::RouteServiceInterface::handleRouteInfoAvailable to propagate route information to the RouteService QML // Singleton which can be used to update the UI. Qul::RouteServiceInterface::handleRouteInfoAvailable(route); // 2. an error happened while receiving the data. // call Qul::RouteService::handleError to propagate error information to the RouteService QML Singleton which can // be used to update the UI. e.g: // Qul::RouteServiceInterface::handleError(Qul::RouteServiceInterface::CommunicationError, "Can't connect!"); } void routeISR(); // simulate calling from interrupt. void MyRouteService::InterruptContext::operator()() const { routeISR(); } void routeISR() { // In this scenario, this event is merely used to signal the receiving of new data from interrupt. // Fetching and handling of the data happens in MyRouteService::onEvent static DataReceivedEvent event; myRouteService.postEventFromInterrupt(event); }