Table of content

What is this :grey_question:

The rules of the game are explained in my original.

62nd Challenge

Challenge

Find the center of multiple co-ordinate points.

Solution :white_check_mark:

Longatiude and Latitude can be easily averaged by adding the coordinates togehter and dividing by the number of components. I will use a free api to resolve strings to coordinates. The api is called GeoAdmin and is limited to Switzerland. The API requires no authentication so it is well suited for this challenge.

And here it is, the solution

    use geocoding::{GeoAdmin,Forward,Point};

    fn main() {

        let addresses= vec!["Locarno","Lugano","Altdorf"];

        let geoadmin = GeoAdmin::new();

        let weight = 1.0/(addresses.len() as f64);
        let mut center = addresses.iter()
        .map(|address|  {
            *geoadmin.forward(address).unwrap().get(0).unwrap()
        }).fold(Point::new(0.0,0.0), |mut acc, x| {
            acc+=x;
            acc
        });

        center=center*weight;

        println!("Center: {:?}",center);
        println!("https://www.google.com/maps/search/{:?},{:?}", center.y(),center.x());
        
    }
    

To see the source see github

Maybe I’ll make this into something bigger, not sure yet.