From 510f8d68c91414cea5f6e8fd360616f857df1db9 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Thu, 25 Feb 2021 10:15:00 -0600 Subject: e --- csci4131/hw3/contacts.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) (limited to 'csci4131/hw3/contacts.js') 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 -- cgit v1.2.3