Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/location to degrees #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Whooot
This project follows the principles of Under-engineering as an art form!

#start the server
navigate to your directory
`python -m "SimpleHTTPServer"`
16 changes: 16 additions & 0 deletions css/compass.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.compass-container {
height: 275px;
width: 300px;
}

.compass-circle {
position: absolute;
height: 40%;
}

.compass-needle {
position: relative;
left: 65px;
height: 200px;
top: 35px;
}
Binary file added images/compass-needle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/compass-without-needle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 118 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,139 @@
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<link rel="stylesheet" href="css/compass.css">

<!-- Favicon
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="icon" type="image/png" href="images/favicon.png">

<!-- js
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<script src="js/compass.js"></script>

<!-- The Map
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<style type="text/css">
html, body { height: 100%; margin: 0; padding: 0; }
/*#map { height: 100%; }*/
#map {
height: 100%;
width: 100%;
position:absolute;
top: 0;
left: 0;
z-index: 0; /* Set z-index to 0 as it will be on a layer below the contact form */
}

#header-box {
padding: 50px;
background-color: rgba(255, 255, 255, 0.65);
z-index: 200;
position: relative;
}

.beforeMap {
position: relative;
z-index: 100;
}
</style>
</head>
<body>
<body onload="woIstMartin()">

<!-- Primary Page Layout
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<div class="container">
<div class="row">
<div class="one-half column" style="margin-top: 25%">
<h4>Basic Page</h4>
<p>This index.html page is a placeholder with the CSS, font and favicon. It's just waiting for you to add some content! If you need some help hit up the <a href="http://www.getskeleton.com">Skeleton documentation</a>.</p>
<div id="header-box">
<h1 class="beforeMap">Wo ist Martin?</h1>
<input class="u-full-width" placeholder="Tell us where you saw Martin" id="searchTextField" onfocus="geolocate()">
<button class="button-primary" onclick="savePosition(markerLat, markerLng)">SAVE</button>
</div>
</div>
<div>
<p> Martin is in this direction</p>
<div class="compass-container">
<img class="compass-circle" src="images/compass-without-needle.png"/>
<img class="compass-needle" src="images/compass-needle.png"/>
</div>
</div>
</div>

<div id="map"></div>
<script type="text/javascript">

var map;
var marker;
var markerLat;
var markerLng;
var autocomplete;

function initMap() {
var myLatLng = {lat: 53.5486471, lng: 9.9861163};

map = new google.maps.Map(document.getElementById('map'), {
center: myLatLng,
zoom: 15
});

map.addListener('click', function(e){
placeMarker(e.latLng, map)
});

initAutocomplete();
}

function placeMarker(latLng, map) {
if(marker){
marker.setMap(null);
}
marker = new google.maps.Marker({
position: latLng,
map: map,
draggable: true
});

// Storing the marker position to send to backend
markerLat = marker.position.lat();
markerLng = marker.position.lng();

map.panTo(latLng);
}

function savePosition(markerLng, markerLat){

var xhttp = new XMLHttpRequest();
var xhttp2 = new XMLHttpRequest();

xhttp.open("GET", "http://localhost:8000/latitude/a/" + markerLat, false);
xhttp.send();

xhttp2.open("GET", "http://localhost:8000/longitude/a/" + markerLng, false);
xhttp2.send();
}

function initAutocomplete() {
autocomplete = new google.maps.places.Autocomplete(
(document.getElementById('searchTextField')),
{types: ['geocode']}
);
}
//todo: Use selected address to set marker and store coordinates








</script>

<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD-ptSi5Ryh7O6cIPYj2WtcwWQgakU08hM&signed_in=true&libraries=places&callback=initMap">
</script>


<!-- End Document
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
</body>
Expand Down
41 changes: 41 additions & 0 deletions js/compass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function woIstMartin(){

var officeCoordinates = {
lat: 53.548648,
lng: 9.9861409
};

var martinCoordinates = {
lat: 53.14677033085084,
lng: 27.2021484375
};

// using this formula http://www.igismap.com/formula-to-find-bearing-or-heading-angle-between-two-points-latitude-longitude/
var locationToDegrees = function(office, martin) {
office.lat = office.lat*Math.PI/180;
office.lng = office.lng*Math.PI/180;
martin.lat = martin.lat*Math.PI/180;
martin.lng = martin.lng*Math.PI/180;

var deltaLng = martin.lng - office.lng;
var x = Math.cos(martin.lat) * Math.sin(deltaLng);
var y = Math.cos(office.lat) * Math.sin(martin.lat) - Math.sin(office.lat) * Math.cos(martin.lat) * Math.cos(deltaLng);
var inRadian = Math.atan2(x, y);
return ((inRadian * 180/Math.PI) + 360) % 360
};

var getMartinCoordinates = function() {
fetch("martin-url/lat", {method: 'DELETE'})
.then(function(lat) {
martinCoordinates.lat = lat;
}).then(function(){
return fetch("martin-url/lng", {method: 'DELETE'})
}).then(function(lng) {
martinCoordinates.lng = lng;
});
};

getMartinCoordinates();
var direction = locationToDegrees(officeCoordinates, martinCoordinates);
document.getElementsByClassName("compass-needle")[0].style.transform="rotate(" + direction + "deg)";
};
16 changes: 16 additions & 0 deletions js/temp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "temp",
"version": "0.0.0",
"description": "",
"main": "server.js",
"dependencies": {
"express": "^4.13.4"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC"
}
17 changes: 17 additions & 0 deletions js/temp/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var express = require('express');
var app = express();

// respond with "hello world" when a GET request is made to the homepage
app.delete('/martin-url/lat', function(req, res) {
res.send(200, "53.14677033085084");
});

app.delete('/martin-url/lng', function(req, res) {
res.send(200, "27.2021484375");
});

app.use('/', express.static('../../'));

app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});