An unofficial Google Maps Platform client library for the Rust programming language. This client currently implements the Directions API, Distance Matrix API, Elevation API, Geocoding API, and Time Zone API.
Welcome
⚠ There are many breaking changes with version 0.4.0. Please review the new examples and change log on how to reformat your code if it no longer compiles. ⚠
This crate is expected to work well and have the more important Google Maps features implemented. It should work well because Reqwest and Serde do most of the heavy lifting! While it's an early release, this crate should work fine as is for most people.
I created this client library because I needed several Google Maps Platform features for a project that I'm working on. So, I've decided to spin my library off into a public crate. This is a very small token of gratitude and an attempt to give back to the Rust community. I hope it saves someone out there some work.
Example Directions API Request
use *;
let mut my_settings = new;
// Example request:
let directions = new
.with_travel_mode
.with_arrival_time
.execute.unwrap;
// Dump entire response:
println!;
Example Distance Matrix API Request
use *;
let mut my_settings = new;
// Example request:
let distance_matrix = new
.execute.unwrap;
// Dump entire response:
println!;
Example Elevation API Positional Request
use *;
let mut my_settings = new;
// Example request:
let elevation = new
// Denver, Colorado, the "Mile High City"
.for_positional_request
.execute.unwrap;
// Dump entire response:
println!;
// Parsing example:
println!;
Example Geocoding API Request
use *;
let mut my_settings = new;
// Example request:
let location = new
.with_address
.execute.unwrap;
// Dump entire response:
println!;
// Parsing example:
for result in &location.results
Example Reverse Geocoding API Request
use *;
let mut my_settings = new;
// Example request:
let location = new
.with_result_type
.execute.unwrap;
// Dump entire response:
println!;
// Parsing example:
for result in &location.results
Example Time Zone API Request
use *;
let mut my_settings = new;
// Example request:
let time_zone = new.execute.unwrap;
// Dump entire response:
println!;
// Parsing example:
use ;
let unix_timestamp =
now.duration_since.unwrap.as_secs;
println!;
println!;
Geolocation API
Google's Geolocation API seems to be offline. While the online documentation
is still available and the API appears configurable through the Google Cloud
Platform console, the Geolocation API responds Status code 404 Not Found
with
an empty body to all requests. This API cannot be implemented until the server
responds as expected.
Feedback
I would like for you to be successful with your project! If this crate is not working for you, doesn't work how you think it should, or if you have requests, or suggestions - please report them to me! I'm not always fast at responding but I will respond. Thanks!
Change Log
-
0.4.4: 2020-02-19: Interface should be stablizing.
-
0.4.4: Added some helper functions for destructuring responses.
-
0.4.4: Ensured response structures are all declared as public.
-
0.4.4: 2020-02-18: Aliased
Distance
andDuration
structs toDirectionsDistance
andDirectionsDuration
respectively to prevent name collisions. -
0.4.4: 2020-02-18: Changed
DirectionsDuration.value
type fromu32
totime::Duration
type. -
0.4.4: 2020-02-18: Dropped my custom Serde deserializer in favour of the
time
crate's built-in Serde feature. -
0.4.4: 2020-02-17: Added support for waypoint optimization.
-
0.4.3: 2020-02-09: Happy 15th birthday to Google Maps!
-
0.4.3: 2020-02-09: Ensured request rate limiting was applied to all API requests.
-
0.4.2: 2020-02-06: Unix timestamps received from the Google Maps Platform are now automatically deserialized into
time::PrimitiveDateTime
structs for convenience. -
0.4.2: 2020-02-06: Removed precision limit for Google Maps Platform requests.
-
0.4.1: 2020-02-06: Added time zone and currency enumerations for look-up tables, conversions, and additional handling to be added in the future.
-
0.4.1: 2020-02-06: Fixed some errors in the examples.
-
0.4.1: 2020-02-05: Some internal restructuring to make the library more consistent. Improved many comments, better documentation.
-
0.4.0: ⚠ Breaking change: API keys are no longer passed directly to Google Maps requests. Now, a structure containing your API key, and several optional settings, is passed instead. For example:
Before:
let location = new
After. Note to Rust newbies: you may need to change the ?
to an .unwrap()
if you're running these examples in your main()
function.
let my_settings = new;
let location = new
-
0.4.0: ⚠ Breaking change: All response structures, such as
DirectionsResponse
, have been altered. -
0.4.0: ⚠ Breaking change: All LatLng enum variants have had the { lat, lng } fields removed in favour of LatLng structs. Use
LatLng::try_from(lat, lng)
to define latitude/longitude pairs. See the updated examples. -
0.4.0: ⚠ Breaking change: The Elevation API methods
positional_request()
&sampled_path_request()
have been renamed tofor_positional_request()
&for_sampled_path_request()
respectively. See the updated examples. -
0.4.0: ⚠ Breaking change: All
f32
fields have been increased tof64
fields. -
0.4.0: Implemented automatic retry with exponential backoff. This client library will now attempt to query the Google Cloud Platform several times before giving up and returning an error. Temporary network hiccups will no longer cause your program to fail.
-
0.4.0: Implemented request rate limiting. Each API can have different request rate limits.
-
0.4.0: Now implements the
log
crate with some logging messages for debugging.
To do
- Track both requests and request elements for rate limiting.
- Make a generic get() function for that can be used by all APIs.
- Look into making APIs optional, i.e. features. Possible? Desirable?
- Look into the prelude::* convention.
- Look into integrating yaiouom.
- Convert explicit query validation to session types wherever reasonable.
- Places API. There are no immediate plans for supporting this API. It's quite big and I have no current need for it. If you would like to have to implemented, please contact me.
- Roads API. There are no immediate plans for supporting this API. It's quite big and I have no current need for it. If you would like to have to implemented, please contact me.