From 689c58b68ec2e90cfc444f791c72deb3e15add0d Mon Sep 17 00:00:00 2001 From: John Hamlett Date: Tue, 19 Jul 2016 11:18:11 -0500 Subject: [PATCH 1/2] Added distance to popup --- .gitignore | 2 ++ static/index.html | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 667e47e..c0f948e 100755 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ db.sqlite3 access_token.json + +.idea/ diff --git a/static/index.html b/static/index.html index 12801f1..32a71cd 100755 --- a/static/index.html +++ b/static/index.html @@ -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 = []; @@ -86,7 +126,7 @@ marker_obj = [v.name, v.latitude,v.longitude]; markers.push(marker_obj); infoWindowContent_obj = ['
' + - '

'+v.name+'

' + + '

'+v.name+'

' + '

is ' + determineDistance(location.coords.latitude, location.coords.longitude, v.latitude, v.longitude) + 'm ' + v.direction + '

will be there for another '+v.time_left+' seconds.

' + '
']; infoWindowContent.push(infoWindowContent_obj); marker_images.push("/static/poke/"+v.id+".ico"); From 31dab0f13f24f31e89cab5af21f0e6b12da134e1 Mon Sep 17 00:00:00 2001 From: John Hamlett Date: Tue, 19 Jul 2016 13:03:26 -0500 Subject: [PATCH 2/2] Added direction to popup text --- static/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/index.html b/static/index.html index 32a71cd..e8c6e59 100755 --- a/static/index.html +++ b/static/index.html @@ -126,7 +126,7 @@ marker_obj = [v.name, v.latitude,v.longitude]; markers.push(marker_obj); infoWindowContent_obj = ['
' + - '

'+v.name+'

' + '

is ' + determineDistance(location.coords.latitude, location.coords.longitude, v.latitude, v.longitude) + 'm ' + v.direction + + '

'+v.name+'

' + '

is ' + determineDistance(location.coords.latitude, location.coords.longitude, v.latitude, v.longitude) + 'm ' + v.direction + 'of you' + '

will be there for another '+v.time_left+' seconds.

' + '
']; infoWindowContent.push(infoWindowContent_obj); marker_images.push("/static/poke/"+v.id+".ico");