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

Added distance to popup #20

Open
wants to merge 2 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
db.sqlite3

access_token.json

.idea/
42 changes: 41 additions & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,46 @@
build_map_update(location);
}

function kmtom(dist){
return Math.round(dist*1000);
}

function deg2Rad(deg){
return deg * (Math.PI / 180);
}

function determineDistance(lat1, long1, lat2, long2){
var r = 6371; //Radius of Earth
var dLat = deg2Rad(lat2-lat1);
var dLon = deg2Rad(long2 - long1);
var a = Math.sin(dLat/2) * Math.sin(dLat/2)
+ Math.cos(deg2Rad(lat1)) * Math.cos(deg2Rad(lat2))
* Math.sin(dLon / 2) * Math.sin(dLon / 2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var d = r * c; // Distance in km
return kmtom(d);
}

function kmtom(dist){
return Math.round(dist*1000);
}

function deg2Rad(deg){
return deg * (Math.PI / 180);
}

function determineDistance(lat1, long1, lat2, long2){
var r = 6371; //Radius of Earth
var dLat = deg2Rad(lat2-lat1);
var dLon = deg2Rad(long2 - long1);
var a = Math.sin(dLat/2) * Math.sin(dLat/2)
+ Math.cos(deg2Rad(lat1)) * Math.cos(deg2Rad(lat2))
* Math.sin(dLon / 2) * Math.sin(dLon / 2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var d = r * c; // Distance in km
return kmtom(d);
}

function build_map_update(location) {
markers = [];
infoWindowContent = [];
Expand All @@ -86,7 +126,7 @@
marker_obj = [v.name, v.latitude,v.longitude];
markers.push(marker_obj);
infoWindowContent_obj = ['<div class="info_content">' +
'<h3>'+v.name+'</h3>' +
'<h3>'+v.name+'</h3>' + '<p> is ' + determineDistance(location.coords.latitude, location.coords.longitude, v.latitude, v.longitude) + 'm ' + v.direction + 'of you' +
'<p>will be there for another '+v.time_left+' seconds.</p>' + '</div>'];
infoWindowContent.push(infoWindowContent_obj);
marker_images.push("/static/poke/"+v.id+".ico");
Expand Down