diff options
author | RossTheRoss <mstrapp@protonmail.com> | 2021-02-25 10:15:00 -0600 |
---|---|---|
committer | RossTheRoss <mstrapp@protonmail.com> | 2021-02-25 10:15:00 -0600 |
commit | 510f8d68c91414cea5f6e8fd360616f857df1db9 (patch) | |
tree | e8834d1d85ec351292141458c6ed8b762107c2cd /csci4131/hw3/contacts.js | |
parent | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... (diff) | |
download | homework-510f8d68c91414cea5f6e8fd360616f857df1db9.tar homework-510f8d68c91414cea5f6e8fd360616f857df1db9.tar.gz homework-510f8d68c91414cea5f6e8fd360616f857df1db9.tar.bz2 homework-510f8d68c91414cea5f6e8fd360616f857df1db9.tar.lz homework-510f8d68c91414cea5f6e8fd360616f857df1db9.tar.xz homework-510f8d68c91414cea5f6e8fd360616f857df1db9.tar.zst homework-510f8d68c91414cea5f6e8fd360616f857df1db9.zip |
e
Diffstat (limited to '')
-rw-r--r-- | csci4131/hw3/contacts.js | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/csci4131/hw3/contacts.js b/csci4131/hw3/contacts.js index 68d5731..8518ef6 100644 --- a/csci4131/hw3/contacts.js +++ b/csci4131/hw3/contacts.js @@ -1,5 +1,3 @@ -document.getElementById("bigboi").classList.add("isntRotating"); - function change(small, row) { document.getElementsByClassName("smol")[row].src = small; } @@ -25,6 +23,19 @@ function check(value) { let map; var center = { lat: 44.9727, lng: -93.23540000000003 }; function initMap() { + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition( + (position) => { + curLoc = { + lat: position.coords.latitude, + lng: position.coords.longitude, + }; + }, + () => { + alert("Geolocation failed. Directions will not work."); + } + ) + } map = new google.maps.Map(document.getElementById("map"), { center: center, zoom: 14, @@ -157,6 +168,54 @@ function deleteMarkers() { searchMarker = []; } +var curLoc, directionsService, directionsRenderer; function directions () { + directionsService = new google.maps.DirectionsService(); + directionsRenderer = new google.maps.DirectionsRenderer(); + document.getElementById("transitList").textContent = ""; + directionsRenderer.setPanel(document.getElementById("transitList")); + directionsRenderer.setMap(map); + var selectedMode = document.getElementById('means').value; + var dest = { + query: document.getElementById("destination").value, + fields: ['name', 'geometry'], + }; + service = new google.maps.places.PlacesService(map); + service.findPlaceFromQuery(dest, function (results, status) { + if (status === google.maps.places.PlacesServiceStatus.OK) { + console.log(results); + doDirections(results[0]); + } + }); +} + +function doDirections(input) { + var means; + var mean = document.getElementsByName('means'); + for (var i = 0; i < mean.length; i++) { + if (mean[i].checked) { + means = mean[i].value; + } + } + var request = { + origin: curLoc, + destination: input.geometry.location, + // Note that JavaScript allows us to access the constant + // using square brackets and a string value as its + // "property." + travelMode: google.maps.TravelMode[means] + }; + directionsService.route(request, function (result, status) { + if (status == 'OK') { + directionsRenderer.setDirections(result); + } + }); } + +function initForm() { + map = new google.maps.Map(document.getElementById("formap"), { + center: center, + zoom: 14, + }); +}
\ No newline at end of file |