mirror of https://github.com/procxx/kepka.git
Add optional support for Yandex.Maps static API
You could enable it via CMake option KEPKA_OPTION_USE_YANDEX_MAPS: cmake -DKEPKA_OPTION_USE_YANDEX_MAPS=ON .. It is used instead of Google Maps API for locations and on location click. Sometimes Google Maps return no maps data. It is related with recent free API usages count decrease from 750k requests to 28k (according to https://habr.com/post/417715/). The code on this commit should be cleaned up and rewritten using Maps API string builders.
This commit is contained in:
parent
419705ed15
commit
17e2bda404
|
@ -13,6 +13,15 @@ if(PROJECT_VERSION_RC)
|
||||||
set(PROJECT_VERSION "${PROJECT_VERSION}-rc${PROJECT_VERSION_RC}")
|
set(PROJECT_VERSION "${PROJECT_VERSION}-rc${PROJECT_VERSION_RC}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
##================================================
|
||||||
|
## Build customizations
|
||||||
|
##================================================
|
||||||
|
option(KEPKA_OPTION_USE_YANDEX_MAPS "Use Yandex.Maps static API for locations (instead Google Maps)" OFF)
|
||||||
|
|
||||||
|
if(KEPKA_OPTION_USE_YANDEX_MAPS)
|
||||||
|
add_definitions("-DKEPKA_USE_YANDEX_MAPS")
|
||||||
|
endif()
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules/")
|
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules/")
|
||||||
|
|
||||||
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.10)
|
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.10)
|
||||||
|
|
|
@ -48,10 +48,20 @@ void LocationClickHandler::onClick(Qt::MouseButton button) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This option could be enabled in core CMakeLists.txt
|
||||||
|
#ifdef KEPKA_USE_YANDEX_MAPS
|
||||||
|
void LocationClickHandler::setup() {
|
||||||
|
// Yandex.Maps accepts ll string in "longitude,latitude" format
|
||||||
|
auto latlon = _coords.lonAsString() + "%2C" + _coords.latAsString();
|
||||||
|
_text = qsl("https://maps.yandex.ru/?ll=") + latlon + qsl("&z=16");
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
void LocationClickHandler::setup() {
|
void LocationClickHandler::setup() {
|
||||||
auto latlon = _coords.latAsString() + ',' + _coords.lonAsString();
|
auto latlon = _coords.latAsString() + ',' + _coords.lonAsString();
|
||||||
_text = qsl("https://maps.google.com/maps?q=") + latlon + qsl("&ll=") + latlon + qsl("&z=16");
|
_text = qsl("https://maps.google.com/maps?q=") + latlon + qsl("&ll=") + latlon + qsl("&z=16");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
LocationManager *locationManager = nullptr;
|
LocationManager *locationManager = nullptr;
|
||||||
|
@ -133,14 +143,28 @@ void LocationManager::getData(LocationData *data) {
|
||||||
w = convertScale(w);
|
w = convertScale(w);
|
||||||
h = convertScale(h);
|
h = convertScale(h);
|
||||||
}
|
}
|
||||||
|
#ifdef KEPKA_USE_YANDEX_MAPS
|
||||||
|
// see https://tech.yandex.ru/maps/doc/staticapi/1.x/dg/concepts/input_params-docpage/ for API parameters reference.
|
||||||
|
auto coords = data->coords.lonAsString() + ',' + data->coords.latAsString(); // Yandex.Maps accepts ll string in "longitude,latitude" format
|
||||||
|
const char *mapsApiUrl = "https://static-maps.yandex.ru/1.x/?ll=";
|
||||||
|
QString mapsApiParams = "&z=%1&size=%2,%3&l=map&scale=%4&pt=";
|
||||||
|
const char *mapsMarkerParams = ",pm2rdl"; // red large marker looking like "9"
|
||||||
|
#else
|
||||||
auto coords = data->coords.latAsString() + ',' + data->coords.lonAsString();
|
auto coords = data->coords.latAsString() + ',' + data->coords.lonAsString();
|
||||||
QString url = qsl("https://maps.googleapis.com/maps/api/staticmap?center=") + coords +
|
const char *mapsApiUrl = "https://maps.googleapis.com/maps/api/staticmap?center=";
|
||||||
qsl("&zoom=%1&size=%2x%3&maptype=roadmap&scale=%4&markers=color:red|size:big|")
|
QString mapsApiParams = "&zoom=%1&size=%2,%3&maptype=roadmap&scale=%4&markers=color:red|size:big|";
|
||||||
|
const char *mapsMarkerParams = "&sensor=false";
|
||||||
|
#endif
|
||||||
|
QString url = // qsl("https://maps.googleapis.com/maps/api/staticmap?center=") + coords +
|
||||||
|
// qsl("&zoom=%1&size=%2x%3&maptype=roadmap&scale=%4&markers=color:red|size:big|")
|
||||||
|
mapsApiUrl + coords + mapsApiParams
|
||||||
.arg(zoom)
|
.arg(zoom)
|
||||||
.arg(w)
|
.arg(w)
|
||||||
.arg(h)
|
.arg(h)
|
||||||
.arg(scale) +
|
.arg(scale) +
|
||||||
coords + qsl("&sensor=false");
|
coords
|
||||||
|
+ mapsMarkerParams;
|
||||||
|
//+ qsl("&sensor=false");
|
||||||
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url)));
|
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url)));
|
||||||
imageLoadings[reply] = data;
|
imageLoadings[reply] = data;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue