Start work on google maps satellite link
This commit is contained in:
parent
78766263b1
commit
24df98878c
@ -2,10 +2,10 @@ use crate::{common::parse_f64, Error, LatLon};
|
||||
use nom::{
|
||||
branch::alt,
|
||||
bytes::complete::tag,
|
||||
character::complete::digit1,
|
||||
character::complete::{self, digit1},
|
||||
combinator::{eof, fail, map, map_res, rest},
|
||||
error::context,
|
||||
sequence::tuple,
|
||||
sequence::{pair, tuple},
|
||||
IResult,
|
||||
};
|
||||
#[cfg(feature = "serde")]
|
||||
@ -24,6 +24,7 @@ const OPENSTREETMAP_ZOOM_LEVEL: u8 = 19;
|
||||
pub struct CoordinateUrls {
|
||||
// TODO: These should be getters only
|
||||
pub google_maps: String,
|
||||
pub google_maps_satellite: String,
|
||||
pub openstreetmap: String,
|
||||
pub waze: String,
|
||||
pub apple_maps: String,
|
||||
@ -51,14 +52,18 @@ impl CoordinateUrls {
|
||||
}
|
||||
|
||||
fn parse_google_maps(i: &str) -> IResult<&str, LatLon> {
|
||||
// TODO: Include this format
|
||||
// https://www.google.com/maps/place/69%C2%B047'21.8%22N+108%C2%B022'45.4%22W/@69.7869906,-108.3727563,15.31z/data=!4m4!3m3!8m2!3d69.7893868!4d-108.3792642
|
||||
|
||||
let (_, url) = Self::parse_url_full(i)?;
|
||||
|
||||
// https://www.google.com/maps/place/69%C2%B047'21.8%22N+108%C2%B022'45.4%22W/@69.7869906,-108.3727563,15.31z/data=!4m4!3m3!8m2!3d69.7893868!4d-108.3792642
|
||||
for segment in url.path_segments().into_iter().flatten() {
|
||||
if let Ok((_str, (_, ret))) = pair(complete::char('@'), LatLon::parse)(segment) {
|
||||
return Ok(("", ret));
|
||||
}
|
||||
}
|
||||
|
||||
for (key, value) in url.query_pairs() {
|
||||
if key == "query" {
|
||||
if let Ok((_str, ret)) = LatLon::parse_full(value.as_ref()) {
|
||||
if let Ok((_str, ret)) = LatLon::parse(value.as_ref()) {
|
||||
return Ok(("", ret));
|
||||
}
|
||||
}
|
||||
@ -129,6 +134,7 @@ impl From<LatLon> for CoordinateUrls {
|
||||
let (lat_str, lon_str) = (format!("{lat}"), format!("{lon}"));
|
||||
let ll = format!("{lat},{lon}");
|
||||
|
||||
// https://developers.google.com/maps/documentation/urls/get-started
|
||||
let google_maps = String::from(
|
||||
Url::parse_with_params(
|
||||
"https://www.google.com/maps/search/",
|
||||
@ -137,6 +143,19 @@ impl From<LatLon> for CoordinateUrls {
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
// TODO: Make this actually open in satellite view
|
||||
let google_maps_satellite = String::from(
|
||||
Url::parse_with_params(
|
||||
"https://www.google.com/maps/search/",
|
||||
&[
|
||||
("api", "1"),
|
||||
("query", ll.as_str()),
|
||||
("basemap", "satellite"),
|
||||
],
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
let openstreetmap = {
|
||||
let mut ret = Url::parse_with_params(
|
||||
"https://www.openstreetmap.org/query",
|
||||
@ -201,6 +220,7 @@ impl From<LatLon> for CoordinateUrls {
|
||||
|
||||
Self {
|
||||
google_maps,
|
||||
google_maps_satellite,
|
||||
openstreetmap,
|
||||
latlon,
|
||||
waze,
|
||||
|
Loading…
Reference in New Issue
Block a user