-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
923d8c5
commit 0ceff94
Showing
37 changed files
with
1,806 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* myLoc.css | ||
* | ||
*/ | ||
|
||
body { | ||
font-family: Arial, Helvetica, sans-serif; | ||
margin: 10px; | ||
} | ||
form, div#location, div#distance { | ||
padding: 5px; | ||
} | ||
|
||
div#map { | ||
margin: 5px; | ||
width: 400px; | ||
height: 400px; | ||
border: 1px solid black; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Where am I?</title> | ||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1"> | ||
<meta charset="utf-8"> | ||
<script src="http://maps.google.com/maps/api/js?sensor=false"></script> | ||
<script src="myLoc.js"></script> | ||
<link rel="stylesheet" href="myLoc.css"> | ||
</head> | ||
<body> | ||
|
||
<div id="location"> | ||
Your location will go here. | ||
</div> | ||
|
||
<div id="distance"> | ||
Distance from WickedlySmart HQ will go here. | ||
</div> | ||
|
||
<div id="map"> | ||
</div> | ||
|
||
</body> | ||
</html> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* myLoc.js */ | ||
|
||
var map = null; | ||
var ourCoords = { | ||
latitude: 47.624851, | ||
longitude: -122.52099 | ||
}; | ||
|
||
window.onload = getMyLocation; | ||
|
||
function getMyLocation() { | ||
if (navigator.geolocation) { | ||
|
||
navigator.geolocation.getCurrentPosition( | ||
displayLocation, | ||
displayError); | ||
} | ||
else { | ||
alert("Oops, no geolocation support"); | ||
} | ||
} | ||
|
||
function displayLocation(position) { | ||
var latitude = position.coords.latitude; | ||
var longitude = position.coords.longitude; | ||
|
||
var div = document.getElementById("location"); | ||
div.innerHTML = "You are at Latitude: " + latitude + ", Longitude: " + longitude; | ||
div.innerHTML += " (with " + position.coords.accuracy + " meters accuracy)"; | ||
|
||
var km = computeDistance(position.coords, ourCoords); | ||
var distance = document.getElementById("distance"); | ||
distance.innerHTML = "You are " + km + " km from the WickedlySmart HQ"; | ||
|
||
showMap(position.coords); | ||
} | ||
|
||
|
||
// --------------------- Ready Bake ------------------ | ||
// | ||
// Uses the Spherical Law of Cosines to find the distance | ||
// between two lat/long points | ||
// | ||
function computeDistance(startCoords, destCoords) { | ||
var startLatRads = degreesToRadians(startCoords.latitude); | ||
var startLongRads = degreesToRadians(startCoords.longitude); | ||
var destLatRads = degreesToRadians(destCoords.latitude); | ||
var destLongRads = degreesToRadians(destCoords.longitude); | ||
|
||
var Radius = 6371; // radius of the Earth in km | ||
var distance = Math.acos(Math.sin(startLatRads) * Math.sin(destLatRads) + | ||
Math.cos(startLatRads) * Math.cos(destLatRads) * | ||
Math.cos(startLongRads - destLongRads)) * Radius; | ||
|
||
return distance; | ||
} | ||
|
||
function degreesToRadians(degrees) { | ||
radians = (degrees * Math.PI)/180; | ||
return radians; | ||
} | ||
|
||
// ------------------ End Ready Bake ----------------- | ||
|
||
function showMap(coords) { | ||
var googleLatAndLong = new google.maps.LatLng(coords.latitude, | ||
coords.longitude); | ||
var mapOptions = { | ||
zoom: 10, | ||
center: googleLatAndLong, | ||
mapTypeId: google.maps.MapTypeId.ROADMAP | ||
}; | ||
var mapDiv = document.getElementById("map"); | ||
map = new google.maps.Map(mapDiv, mapOptions); | ||
|
||
// add the user marker | ||
var title = "Your Location"; | ||
var content = "You are here: " + coords.latitude + ", " + coords.longitude; | ||
addMarker(map, googleLatAndLong, title, content); | ||
|
||
} | ||
|
||
function addMarker(map, latlong, title, content) { | ||
var markerOptions = { | ||
position: latlong, | ||
map: map, | ||
title: title, | ||
clickable: true | ||
}; | ||
var marker = new google.maps.Marker(markerOptions); | ||
|
||
var infoWindowOptions = { | ||
content: content, | ||
position: latlong | ||
}; | ||
|
||
var infoWindow = new google.maps.InfoWindow(infoWindowOptions); | ||
|
||
google.maps.event.addListener(marker, 'click', function() { | ||
infoWindow.open(map); | ||
}); | ||
} | ||
|
||
|
||
function displayError(error) { | ||
var errorTypes = { | ||
0: "Unknown error", | ||
1: "Permission denied", | ||
2: "Position is not available", | ||
3: "Request timeout" | ||
}; | ||
var errorMessage = errorTypes[error.code]; | ||
if (error.code == 0 || error.code == 2) { | ||
errorMessage = errorMessage + " " + error.message; | ||
} | ||
var div = document.getElementById("location"); | ||
div.innerHTML = errorMessage; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* myLoc.css | ||
* | ||
*/ | ||
|
||
body { | ||
font-family: Arial, Helvetica, sans-serif; | ||
margin: 10px; | ||
} | ||
div#location, div#distance { | ||
padding: 5px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Where am I?</title> | ||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1"> | ||
<meta charset="utf-8"> | ||
<script src="myLoc.js"></script> | ||
<link rel="stylesheet" href="myLoc.css"> | ||
</head> | ||
<body> | ||
|
||
<div id="location"> | ||
Your location will go here. | ||
</div> | ||
|
||
<div id="distance"> | ||
Distance from WickedlySmart HQ will go here. | ||
</div> | ||
|
||
</body> | ||
</html> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* myLoc.js */ | ||
|
||
var ourCoords = { | ||
latitude: 47.624851, | ||
longitude: -122.52099 | ||
}; | ||
|
||
window.onload = getMyLocation; | ||
|
||
function getMyLocation() { | ||
if (navigator.geolocation) { | ||
|
||
navigator.geolocation.getCurrentPosition( | ||
displayLocation, | ||
displayError); | ||
} | ||
else { | ||
alert("Oops, no geolocation support"); | ||
} | ||
} | ||
|
||
function displayLocation(position) { | ||
var latitude = position.coords.latitude; | ||
var longitude = position.coords.longitude; | ||
|
||
var div = document.getElementById("location"); | ||
div.innerHTML = "You are at Latitude: " + latitude + ", Longitude: " + longitude; | ||
|
||
var km = computeDistance(position.coords, ourCoords); | ||
var distance = document.getElementById("distance"); | ||
distance.innerHTML = "You are " + km + " km from the WickedlySmart HQ"; | ||
|
||
} | ||
|
||
|
||
// --------------------- Ready Bake ------------------ | ||
// | ||
// Uses the Spherical Law of Cosines to find the distance | ||
// between two lat/long points | ||
// | ||
function computeDistance(startCoords, destCoords) { | ||
var startLatRads = degreesToRadians(startCoords.latitude); | ||
var startLongRads = degreesToRadians(startCoords.longitude); | ||
var destLatRads = degreesToRadians(destCoords.latitude); | ||
var destLongRads = degreesToRadians(destCoords.longitude); | ||
|
||
var Radius = 6371; // radius of the Earth in km | ||
var distance = Math.acos(Math.sin(startLatRads) * Math.sin(destLatRads) + | ||
Math.cos(startLatRads) * Math.cos(destLatRads) * | ||
Math.cos(startLongRads - destLongRads)) * Radius; | ||
|
||
return distance; | ||
} | ||
|
||
function degreesToRadians(degrees) { | ||
radians = (degrees * Math.PI)/180; | ||
return radians; | ||
} | ||
|
||
// ------------------ End Ready Bake ----------------- | ||
|
||
|
||
function displayError(error) { | ||
var errorTypes = { | ||
0: "Unknown error", | ||
1: "Permission denied", | ||
2: "Position is not available", | ||
3: "Request timeout" | ||
}; | ||
var errorMessage = errorTypes[error.code]; | ||
if (error.code == 0 || error.code == 2) { | ||
errorMessage = errorMessage + " " + error.message; | ||
} | ||
var div = document.getElementById("location"); | ||
div.innerHTML = errorMessage; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* myLoc.css | ||
* | ||
*/ | ||
|
||
body { | ||
font-family: Arial, Helvetica, sans-serif; | ||
margin: 10px; | ||
} | ||
form, div#location, div#distance { | ||
padding: 5px; | ||
} | ||
|
||
div#map { | ||
margin: 5px; | ||
width: 400px; | ||
height: 400px; | ||
border: 1px solid black; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Wherever you go, there you are</title> | ||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1"> | ||
<meta charset="utf-8"> | ||
<script src="http://maps.google.com/maps/api/js?sensor=false"></script> | ||
<script src="myLoc.js"></script> | ||
<link rel="stylesheet" href="myLoc.css"> | ||
</head> | ||
<body> | ||
|
||
<form> | ||
<input type="button" id="watch" value="Watch me"> | ||
<input type="button" id="clearWatch" value="Clear watch"> | ||
</form> | ||
|
||
<div id="location"> | ||
Your location will go here. | ||
</div> | ||
|
||
<div id="distance"> | ||
Distance from WickedlySmart HQ will go here. | ||
</div> | ||
|
||
<div id="map"> | ||
</div> | ||
|
||
</body> | ||
</html> | ||
|
||
|
Oops, something went wrong.