diff options
author | RossTheRoss <mstrapp@protonmail.com> | 2021-02-23 21:29:57 -0600 |
---|---|---|
committer | RossTheRoss <mstrapp@protonmail.com> | 2021-02-23 21:29:57 -0600 |
commit | 01b2feee26eb0cb2c968a361a9ac2723dbfc2352 (patch) | |
tree | 2c31489383e666dd5988b419f82eb8490387cf96 /csci4131/hw3/contacts.js | |
parent | brolken (diff) | |
download | homework-01b2feee26eb0cb2c968a361a9ac2723dbfc2352.tar homework-01b2feee26eb0cb2c968a361a9ac2723dbfc2352.tar.gz homework-01b2feee26eb0cb2c968a361a9ac2723dbfc2352.tar.bz2 homework-01b2feee26eb0cb2c968a361a9ac2723dbfc2352.tar.lz homework-01b2feee26eb0cb2c968a361a9ac2723dbfc2352.tar.xz homework-01b2feee26eb0cb2c968a361a9ac2723dbfc2352.tar.zst homework-01b2feee26eb0cb2c968a361a9ac2723dbfc2352.zip |
JS sucks
Diffstat (limited to '')
-rw-r--r-- | csci4131/hw3/contacts.js | 84 |
1 files changed, 80 insertions, 4 deletions
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: "<b>" + locations[x].name + "</b>" + + "<br>" + locations[x].formatted_address + }, + }); + } + } else { + var marker = new google.maps.Marker({ + map, + title: locations[x].name, + position: locations[x].geometry.location, + data: { + content: "<b>" + locations[x].name + "</b>" + + "<br>" + 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); + } + }) + } +} |