Comments (3)
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.
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 forreqwest
.
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.
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)
- Distance matrix api response elements are private HOT 1
- [Feature request] Place autocomplete API HOT 2
- Handle optional Geocoding fields in response HOT 3
- Deserialization of PlaceType is not invertible. HOT 2
- Feature Request - nearby_search HOT 4
- Add landmark to place type HOT 1
- `Result::unwrap()` on an `Err` value: Google Maps Directions API client in the Serde JSON library: missing field `html_instructions` HOT 3
- native-tls included in dependencies even with rustls enabled HOT 4
- nearby_search::Request::execute() - Error: "Serde JSON library: missing field `address_components`" HOT 1
- Cannot be used in async context, conflicts with parent runtime HOT 7
- Distance matrix struct, makes a request with coordinates in degrees HOT 4
- Support providing a preconfigured reqwest client to ClientSettings HOT 2
- Switch from `log` to `tracing` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google_maps.