Git Product home page Git Product logo

Comments (3)

leontoeides avatar leontoeides commented on June 12, 2024 1

Just a quick note that I've implemented this change. Sounds like Google Maps Platform API's will have to include CORS headers if they want WASM clients to connect.

from google_maps.

leontoeides avatar leontoeides commented on June 12, 2024

Never thought of this situation! Later today I will see about issuing an update where:

  • Google Maps client will come with all of the Reqwest fixins' by default.
  • If a crate turns off Google Maps default-features all desired features must be manually added, even for reqwest.

There is also another option:

use google_maps::prelude::*;

let google_maps_client = ClientSettings::new("YOUR_GOOGLE_API_KEY_HERE");

// Get query string from builder pattern:
let query_string = google_maps_client.time_zone(
     LatLng::try_from(dec!(50.090_903), dec!(14.400_512))?,
     Utc::now()
).query_string();

// Insert your favourite HTTP client here:
let json = reqwest::get(
    // query_string.0 = "https://maps.googleapis.com/maps/api/timezone/json?"
    query_string.0 + &query_string.1
).await?.text().await?;

// Parse JSON string into a TimeZoneResponse structure:
let time_zone: TimeZoneResponse = json.parse()?;

// Dump entire response:
println!("{:#?}", time_zone);

Putting the API key in the client is not necessarily bad practice! Just restrict the key to the necessary API's, and make sure you put quotas you're comfortable with - so you don't get a huge bill. https://console.cloud.google.com/google/maps-apis/quotas

from google_maps.

E-gy avatar E-gy commented on June 12, 2024

It looks like this approach isn't the best after all.

See, the Google Maps API this is using seems to be designed for servers first. Trying to access it via fetch simply leads to CORS getting in the way (the servers don't include CORS headers, and getting opaque responses is useless).

The correct way to use Maps API client side, for now at least, is via Google Maps JavaScript API + Rust bindings via wasm_bindgen (which do not seem to exist as a crate at the moment).
... or write a server proxying the requests in Rust, and call that instead.

In light of Google's inherent limitations, i consider this issue as irrelevant to this crate. Sorry for bothering.

from google_maps.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.