/// Get elevation from the name of a location.
Get elevation from the name of a location.
Get elevation from the name of a location .
pub async fn from_location(name: &str) -> Result<Self, ElevationError> {
        let uri = &format!(
            "https://nominatim.openstreetmap.org/search?q={}&format=json",
            name.replace(" ", "+")
        );
        let geocode = match surf::get(uri).recv_string().await {
            Ok(data) => data,
            Err(error) => return Err(ElevationError::Http(error.to_string())),
        };
        let geocode_json: Value = match serde_json::from_str(&geocode) {
            Ok(data) => data,
            Err(error) => return Err(ElevationError::Json(error.to_string())),
        };
        let lat = match &geocode_json[0]["lat"] {
            Value::String(s) => s,
            _ => {
                return Err(ElevationError::Json(
                    "couldn't find the geocoded latitude".to_string(),
                ))
            }
        };
        let lon = match &geocode_json[0]["lon"] {
            Value::String(s) => s,
            _ => {
                return Err(ElevationError::Json(
                    "couldn't find the geocoded longitude".to_string(),
                ))
            }
        };
        let lat: f64 = match lat.parse() {
            Ok(data) => data,
            Err(error) => return Err(ElevationError::Json(error.to_string())),
        };
        let lon: f64 = match lon.parse() {
            Ok(data) => data,
            Err(error) => return Err(ElevationError::Json(error.to_string())),
        };
        return Self::from_coords(lat, lon).await;
    }
pub async fn from_location ( name : & str ) -> Result < Self , ElevationError > { let uri = & format ! ( " " name replace ( " " " " ) ) ; let geocode = match surf :: get ( uri ) . recv_string ( ) . await { Ok ( data ) => data , Err ( error ) => return Err ( ElevationError :: Http ( error . to_string ( ) ) ) , } ; let geocode_json : Value = match serde_json :: from_str ( & geocode ) { Ok ( data ) => data , Err ( error ) => return Err ( ElevationError :: Json ( error . to_string ( ) ) ) , } ; let lat = match & geocode_json [ 0 ] [ " " ] { Value :: String ( s ) => s , _ => { return Err ( ElevationError :: Json ( " " . to_string ( ) , ) ) } } ; let lon = match & geocode_json [ 0 ] [ " " ] { Value :: String ( s ) => s , _ => { return Err ( ElevationError :: Json ( " " . to_string ( ) , ) ) } } ; let lat : f64 = match lat . parse ( ) { Ok ( data ) => data , Err ( error ) => return Err ( ElevationError :: Json ( error . to_string ( ) ) ) , } ; let lon : f64 = match lon . parse ( ) { Ok ( data ) => data , Err ( error ) => return Err ( ElevationError :: Json ( error . to_string ( ) ) ) , } ; return Self :: from_coords ( lat , lon ) . await ; }
Get elevation from the name of a location.
Get elevation from the name of a location .
name
&str