/// Get elevations from multiple coordinates in one request.
Get elevations from multiple coordinates in one request.
Get elevations from multiple coordinates in one request .
pub async fn from_multiple_coords(coords: Vec<[f64; 2]>) -> Result<Vec<Self>, ElevationError> {
        let mut uri = String::from("https://elevation-api.io/api/elevation?points=");
        for coord in &coords {
            uri.push_str(&format!("({},{}),", coord[0], coord[1]));
        }
        let res = match surf::get(&uri).recv_string().await {
            Ok(data) => data,
            Err(error) => return Err(ElevationError::Http(error.to_string())),
        };
        let json: Value = match serde_json::from_str(&res) {
            Ok(data) => data,
            Err(error) => return Err(ElevationError::Json(error.to_string())),
        };
        let mut results: Vec<Self> = Vec::new();
        for (x, _) in coords.into_iter().enumerate() {
            let (latitude, longitude, elevation) = match Self::parse_json(&json["elevations"][x]) {
                Ok(data) => data,
                Err(error) => return Err(error),
            };
            let resolution = match &json["resolution"] {
                Value::String(s) => s,
                _ => {
                    return Err(ElevationError::Json(
                        "couldn't find the resolution".to_string(),
                    ))
                }
            };
            let s = Self {
                latitude,
                longitude,
                elevation,
                resolution: resolution.to_string(),
            };
            results.push(s);
        }
        return Ok(results);
    }
pub async fn from_multiple_coords ( coords : Vec < [ f64 ; 2 ] > ) -> Result < Vec < Self > , ElevationError > { let mut uri = String :: from ( " " ) ; for coord in & coords { uri . push_str ( & format ! ( " " coord [ 0 ] coord [ 1 ] ) ) ; } let res = match surf :: get ( & uri ) . recv_string ( ) . await { Ok ( data ) => data , Err ( error ) => return Err ( ElevationError :: Http ( error . to_string ( ) ) ) , } ; let json : Value = match serde_json :: from_str ( & res ) { Ok ( data ) => data , Err ( error ) => return Err ( ElevationError :: Json ( error . to_string ( ) ) ) , } ; let mut results : Vec < Self > = Vec :: new ( ) ; for ( x , _ ) in coords . into_iter ( ) . enumerate ( ) { let ( latitude , longitude , elevation ) = match Self :: parse_json ( & json [ " " ] [ x ] ) { Ok ( data ) => data , Err ( error ) => return Err ( error ) , } ; let resolution = match & json [ " " ] { Value :: String ( s ) => s , _ => { return Err ( ElevationError :: Json ( " " . to_string ( ) , ) ) } } ; let s = Self { latitude , longitude , elevation , resolution : resolution . to_string ( ) , } ; results . push ( s ) ; } return Ok ( results ) ; }
Get elevations from multiple coordinates in one request.
Get elevations from multiple coordinates in one request .
coords
Vec<[f64; 2]>