Skip to content

Commit

Permalink
add coord gps in result
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGANGLOFF committed Apr 11, 2024
1 parent b950c30 commit 79abb29
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions common/src/google/nearly_place_model.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use dotenv_codegen::dotenv;
use serde::{Deserialize, Serialize};
use serde_json::Value;

// Suite de structure pour gérer le JSON de Google API Place
#[derive(Serialize, Deserialize, Debug)]
struct TypePlace {
html_attributions: Vec<serde_json::Value>,
html_attributions: Vec<Value>,
next_page_token: Option<String>,
results: Vec<Place>,
status: String,
Expand Down Expand Up @@ -74,22 +75,26 @@ pub struct Emplacement {
rating: f64,
address: String,
picture: String,
lat: f64,
long: f64,
}

impl Emplacement {
fn new(name: String, rating: f64, address: String, picture: String) -> Self {
fn new(name: String, rating: f64, address: String, picture: String, lat: f64, long: f64) -> Self {
Self {
name,
rating,
address,
picture,
lat,
long
}
}
}

// Cette fonction sert à récupérer depuis le JSON de l'API Google Place les informations qui nous intéressent
// On récupère le nom, la note, l'adresse et la photo de l'endroit qu'on regroupe dans un vecteur de "Emplacement"
pub fn exploit_json(value: serde_json::Value) -> Result<Vec<Emplacement>, anyhow::Error> {
pub fn exploit_json(value: Value) -> Result<Vec<Emplacement>, anyhow::Error> {
let data: TypePlace = serde_json::from_value(value.clone())?;
let mut place_list = Vec::new();
for place in data.results {
Expand All @@ -104,8 +109,9 @@ pub fn exploit_json(value: serde_json::Value) -> Result<Vec<Emplacement>, anyhow
};

let rating = place.rating.unwrap_or_else(|| 0.0);

let place = Emplacement::new(place.name, rating, place.vicinity, picture);
let lat = place.geometry.location.lat;
let long = place.geometry.location.lng;
let place = Emplacement::new(place.name, rating, place.vicinity, picture, lat, long);
place_list.push(place);
}
Ok(place_list)
Expand Down

0 comments on commit 79abb29

Please sign in to comment.