2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Search for venues by location.

This commit is contained in:
John Preston
2024-07-11 18:15:17 +02:00
parent de52ac6b28
commit a130bb1be6
6 changed files with 213 additions and 36 deletions

View File

@@ -148,7 +148,7 @@ void ResolveLocationAddressGeneric(
}
}
};
add({ u"address"_q, u"street"_q, u"neighborhood"_q });
add({ /*u"address"_q, u"street"_q, */u"neighborhood"_q });
add({ u"place"_q, u"region"_q });
add({ u"country"_q });
finishWith({ .name = names.join(", ") });
@@ -215,4 +215,29 @@ void ResolveLocationAddress(
Platform::ResolveLocationAddress(location, language, std::move(done));
}
bool AreTheSame(const GeoLocation &a, const GeoLocation &b) {
if (a.accuracy != GeoLocationAccuracy::Exact
|| b.accuracy != GeoLocationAccuracy::Exact) {
return false;
}
const auto normalize = [](float64 value) {
value = std::fmod(value + 180., 360.);
return (value + (value < 0. ? 360. : 0.)) - 180.;
};
constexpr auto kEpsilon = 0.0001;
const auto lon1 = normalize(a.point.y());
const auto lon2 = normalize(b.point.y());
const auto diffLat = std::abs(a.point.x() - b.point.x());
if (std::abs(a.point.x()) >= (90. - kEpsilon)
|| std::abs(b.point.x()) >= (90. - kEpsilon)) {
return diffLat <= kEpsilon;
}
auto diffLon = std::abs(lon1 - lon2);
if (diffLon > 180.) {
diffLon = 360. - diffLon;
}
return diffLat <= kEpsilon && diffLon <= kEpsilon;
}
} // namespace Core

View File

@@ -33,12 +33,10 @@ struct GeoLocation {
explicit operator bool() const {
return !failed();
}
friend inline bool operator==(
const GeoLocation&,
const GeoLocation&) = default;
};
[[nodiscard]] bool AreTheSame(const GeoLocation &a, const GeoLocation &b);
struct GeoAddress {
QString name;