From 01b2feee26eb0cb2c968a361a9ac2723dbfc2352 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Tue, 23 Feb 2021 21:29:57 -0600 Subject: JS sucks --- csci4131/hw3/contacts.js | 84 +++++++++++++++++++++++++++++++++++++++++--- csci4131/hw3/myContacts.html | 16 +++++---- csci4131/hw3/style.css | 3 ++ 3 files changed, 92 insertions(+), 11 deletions(-) (limited to 'csci4131') diff --git a/csci4131/hw3/contacts.js b/csci4131/hw3/contacts.js index 50f72d8..8701aae 100644 --- a/csci4131/hw3/contacts.js +++ b/csci4131/hw3/contacts.js @@ -16,10 +16,17 @@ function dizzy() { } isRotating^=1; } +function check(value) { + if(value==="Other") + document.getElementById('others').style.display = 'block'; + else + document.getElementById('others').style.display = 'none'; +} let map; +var center = { lat: 44.9727, lng: -93.23540000000003 }; function initMap() { map = new google.maps.Map(document.getElementById("map"), { - center: { lat: 44.9727, lng: -93.23540000000003 }, + center: center, zoom: 14, }); @@ -37,13 +44,12 @@ function initMap() { locations[kludge++] = results[0]; } if (kludge == entries.length) { - addPoints(locations); + addPointsContacts(locations); } }); } } - -function addPoints(locations) { +function addPointsContacts(locations) { for (x in locations) { var newEntry = document.getElementsByClassName("entry")[x]; var marker = new google.maps.Marker({ @@ -70,3 +76,73 @@ function addPoints(locations) { }) } } +var service; +var otherRadius; +function searchPlaces() { + var request; + if (document.getElementById("places").value!="Other") { + request = { + location: center, + radius: document.getElementById("distance").value, + type: document.getElementById("places").value, + }; + service = new google.maps.places.PlacesService(map); + service.nearbySearch(request, (results, status) => { + if (status === google.maps.places.PlacesServiceStatus.OK && results) { + addPointsSearch(results, false); + } + }); + } else { + request = { + location: center, + radius: document.getElementById("distance").value, + query: document.getElementById("others").value, + }; + otherRadius = request.radius; + console.log(otherRadius); + service = new google.maps.places.PlacesService(map); + service.textSearch(request, (results, status) => { + if (status === google.maps.places.PlacesServiceStatus.OK && results) { + addPointsSearch(results, true); + } + }); + } +} +function addPointsSearch(locations, isOther) { + console.log(locations); + for (x in locations) { + var marker; + if (isOther) { + if (google.maps.geometry.spherical.computeDistanceBetween(locations[x].geometry.location, center) < parseInt(otherRadius)) { + marker = new google.maps.Marker({ + map, + title: locations[x].name, + position: locations[x].geometry.location, + data: { + content: "" + locations[x].name + "" + + "
" + locations[x].formatted_address + }, + }); + } + } else { + var marker = new google.maps.Marker({ + map, + title: locations[x].name, + position: locations[x].geometry.location, + data: { + content: "" + locations[x].name + "" + + "
" + locations[x].vicinity + }, + }); + } + + marker.addListener('click', function () { + if (!this.infoWindow) { + this.infoWindow = new google.maps.InfoWindow({ + content: this.data.content, + }); + this.infoWindow.open(map, this); + } + }) + } +} diff --git a/csci4131/hw3/myContacts.html b/csci4131/hw3/myContacts.html index 6981209..8e722e0 100644 --- a/csci4131/hw3/myContacts.html +++ b/csci4131/hw3/myContacts.html @@ -81,20 +81,22 @@
TRANSIT PLACEHOLDER
- + diff --git a/csci4131/hw3/style.css b/csci4131/hw3/style.css index aa9ae2c..2be7a2b 100644 --- a/csci4131/hw3/style.css +++ b/csci4131/hw3/style.css @@ -82,6 +82,9 @@ tr:nth-child(odd) { .inputBox:nth-child(odd) { background-color: burlywood; } +#others { + display:none; +} /* Form */ .Form { -- cgit v1.2.3