Skip to content

Commit 1c97ab0

Browse files
committed
Added MapBox static map example.
1 parent f056d2a commit 1c97ab0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,22 @@ See [Strava::Models::Activity](lib/strava/models/activity.rb) for all available
154154
Use `map.summary_polyline` and combine with [polylines](https://github.com/joshuaclayton/polylines) to parse the activity map and to construct a Google maps URL with start and end markers.
155155

156156
```ruby
157+
require 'CGI'
158+
require 'polylines'
159+
157160
map = activity.map # => Strava::Models::Map
158161

159162
decoded_summary_polyline = Polylines::Decoder.decode_polyline(map.summary_polyline)
160163
start_latlng = decoded_summary_polyline[0]
161164
end_latlng = decoded_summary_polyline[-1]
162165

166+
# Google Maps Static API
163167
google_maps_api_key = ENV['GOOGLE_STATIC_MAPS_API_KEY']
168+
google_image_url = "https://maps.googleapis.com/maps/api/staticmap?maptype=roadmap&path=enc:#{CGI.escape(map.summary_polyline)}&size=800x800&markers=color:yellow|label:S|#{start_latlng[0]},#{start_latlng[1]}&markers=color:green|label:F|#{end_latlng[0]},#{end_latlng[1]}&key=#{google_maps_api_key}"
164169

165-
google_image_url = "https://maps.googleapis.com/maps/api/staticmap?maptype=roadmap&path=enc:#{map.summary_polyline}&key=#{google_maps_api_key}&size=800x800&markers=color:yellow|label:S|#{start_latlng[0]},#{start_latlng[1]}&markers=color:green|label:F|#{end_latlng[0]},#{end_latlng[1]}"
170+
# MapBox Static API
171+
mapbox_access_token = ENV['MAPBOX_ACCESS_TOKEN']
172+
mapbox_image_url = "https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/path-5+787af2-1.0(#{CGI.escape(map.summary_polyline)}),pin-s-s+e5b22e(#{start_latlng[1]},#{start_latlng[0]}),pin-s-f+89ae00(#{end_latlng[1]},#{end_latlng[0]})/auto/800x800?access_token=#{mapbox_access_token}"
166173
```
167174

168175
See [Strava::Models::Map](lib/strava/models/map.rb) for all available properties.

0 commit comments

Comments
 (0)