JavaScript
In this project you will create an interactive map for a cycling club in Boulder, Colorado,
allowing cyclists to view a map with directions between two popular cycling destinations. To
complete this project, you will need to set up a Google Cloud account along with an API key to
access the Google Maps, Directions Service, and Directions Renderer APIs. A preview of the
completed page is shown in Figure 10-42.
Do the following:
1. Use your code editor to open the project10-03_txt.html and project10-03_txt.js files from the
js10 c
project03 folder. Enter your name and the date in the comment section of each file and save them
as
project10-03.html and project10-03.js, respectively.
2. Go to the project10-03.html file in your code editor. Add a script element linked to the
project10-03js file.
Defer the loading of the script until after the page is loaded.
3. Add another script element with the following src attribute:
https://maps.googleapis.com/maps/
api/js?key=key&callback=showMap where key is your Google Maps API key. Also defer this
script until
after the page is loaded.
4. Close the file, saving your changes and then go to the project10-03.js file in your code editor.
Steps 5
through 10 should all be down within the showMap() function. Several variables have already
been
declared for you.
5. Use the new google.maps.DirectionsService() object constructor to create a DirectionsService
object named bikeFind.
6. Use the new google.maps.DirectionsRenderer() object constructor to create a
DirectionsRenderer object named bikeDraw.
7. Create a LatLng object named Boulder storing within it a latitude of 40.01753 and a longitude
of
-105.26496.
8. Use the new google.maps.Map() object constructor to instantiate a new Google map named
myMap. Set the
zoom level to 12 and center the map on Boulder.
9. Create event listeners for the startingPoint and endingPoint selection lists, running the
drawRoute()
function in response to the change event.
10. Create the drawRoute() function. Within the function insert an if statement that tests whether
the selected index for the startingPoint and endingPoint selection lists are both not equal to 0. If
true, then do the
following:
a. Define a route object named bikeRoute with an origin at startingPoint.value and a destination
at
endingPoint.value. Set the travelMode option to BICYCLING.
b. Apply the route() method to the bikeFind object generating directions between the starting and
ending
points. If the status of the request is OK then (i) apply the setDirections() method to bikeDraw
object request directions from the directions service, (ii) apply the setMap() method to bikeDraw
to
display the route within myMap, and (iii) apply the setPanel() method to bikeDraw to display the
turnby-turn directions within the bikeDirections object. If the status is not OK then change the
text content of the bikeDirections object to Directions
Unavailable: status.
11. Save your changes to the file and then load project10-03.
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
JavaScriptIn this project you will create an interactive map for a.pdf
1. JavaScript
In this project you will create an interactive map for a cycling club in Boulder, Colorado,
allowing cyclists to view a map with directions between two popular cycling destinations. To
complete this project, you will need to set up a Google Cloud account along with an API key to
access the Google Maps, Directions Service, and Directions Renderer APIs. A preview of the
completed page is shown in Figure 10-42.
Do the following:
1. Use your code editor to open the project10-03_txt.html and project10-03_txt.js files from the
js10 c
project03 folder. Enter your name and the date in the comment section of each file and save them
as
project10-03.html and project10-03.js, respectively.
2. Go to the project10-03.html file in your code editor. Add a script element linked to the
project10-03js file.
Defer the loading of the script until after the page is loaded.
3. Add another script element with the following src attribute:
https://maps.googleapis.com/maps/
api/js?key=key&callback=showMap where key is your Google Maps API key. Also defer this
script until
after the page is loaded.
4. Close the file, saving your changes and then go to the project10-03.js file in your code editor.
Steps 5
through 10 should all be down within the showMap() function. Several variables have already
been
declared for you.
5. Use the new google.maps.DirectionsService() object constructor to create a DirectionsService
object named bikeFind.
6. Use the new google.maps.DirectionsRenderer() object constructor to create a
DirectionsRenderer object named bikeDraw.
7. Create a LatLng object named Boulder storing within it a latitude of 40.01753 and a longitude
of
-105.26496.
8. Use the new google.maps.Map() object constructor to instantiate a new Google map named
myMap. Set the
zoom level to 12 and center the map on Boulder.
2. 9. Create event listeners for the startingPoint and endingPoint selection lists, running the
drawRoute()
function in response to the change event.
10. Create the drawRoute() function. Within the function insert an if statement that tests whether
the selected index for the startingPoint and endingPoint selection lists are both not equal to 0. If
true, then do the
following:
a. Define a route object named bikeRoute with an origin at startingPoint.value and a destination
at
endingPoint.value. Set the travelMode option to BICYCLING.
b. Apply the route() method to the bikeFind object generating directions between the starting and
ending
points. If the status of the request is OK then (i) apply the setDirections() method to bikeDraw
object request directions from the directions service, (ii) apply the setMap() method to bikeDraw
to
display the route within myMap, and (iii) apply the setPanel() method to bikeDraw to display the
turnby-turn directions within the bikeDirections object. If the status is not OK then change the
text content of the bikeDirections object to Directions
Unavailable: status.
11. Save your changes to the file and then load project10-03.html in your browser. Verify that a
map of Boulder,Colorado appears in the left box. Verify that when you select starting and ending
points from the two list boxes,a route is drawn on the map and turn-by-turn directions are
provided between the two points.
Filename: project10-3.html
Hands-on Project 10-3
Hands-on Project 10-3
Boulder Cycling Routes
Choose an origin and a destination of your cycling outingStarting PointFolsom FieldNCAREben
G. Fine ParkEldorado SpringsValmont Bike ParkKossler LakeRocky FlatsFoothills
ParkJamestownEnding PointFolsom FieldNCAREben G. Fine ParkEldorado SpringsValmont
Bike ParkKossler LakeRocky FlatsFoothills ParkJamestown
--------------------------------------------------------------------------------------------
Filename: project10-03.js
"use strict";