-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Function and examples ( http://0.0.0.0:8000/webapp/geolocation ) to g…
…eolocation. $.pos() ask for geolocation just the first time, and save result for the next time. $.pos() admit two function as parameters, one to success, and another to fail.
- Loading branch information
Showing
4 changed files
with
104 additions
and
1 deletion.
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
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,49 @@ | ||
function reset() { | ||
$._pos=null; | ||
} | ||
function resetMap () { | ||
document.getElementById("mapholder").innerHTML = ""; | ||
} | ||
function getLocation() { | ||
$.pos( | ||
function(position){ | ||
var latlon = position.coords.latitude + "," + position.coords.longitude; | ||
var img_url = "http://maps.googleapis.com/maps/api/staticmap?center="+latlon+"&zoom=14&size=400x300&sensor=false"; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
s-nt-s
Author
Contributor
|
||
document.getElementById("mapholder").innerHTML = "<img src='"+img_url+"'>"; | ||
}, | ||
function(error){ | ||
var x = document.getElementById("demo"); | ||
if (error.UNSUPPORTED) { | ||
x.innerHTML = "Geolocation is not supported by this browser."; | ||
return; | ||
} | ||
switch(error.code) { | ||
case error.PERMISSION_DENIED: | ||
x.innerHTML = "User denied the request for Geolocation."; | ||
break; | ||
case error.POSITION_UNAVAILABLE: | ||
x.innerHTML = "Location information is unavailable."; | ||
break; | ||
case error.TIMEOUT: | ||
x.innerHTML = "The request to get user location timed out."; | ||
break; | ||
case error.UNKNOWN_ERROR: | ||
x.innerHTML = "An unknown error occurred."; | ||
break; | ||
} | ||
} | ||
); | ||
} | ||
function getLocation2() { | ||
alert(JSON.stringify($.pos())); | ||
} | ||
|
||
function getLocation3() { | ||
$.pos( | ||
function() { | ||
alert("OK"); | ||
},function() { | ||
alert("KO"); | ||
} | ||
); | ||
} |
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,22 @@ | ||
{% extends "base.html" %} | ||
{% load static %} | ||
|
||
{% block javascript_level2 %} | ||
<script type="text/javascript" src="{% static 'webapp/js/geoexample.js' %}" defer="defer"></script> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
|
||
|
||
|
||
<p id="demo">Click the button to get your position.</p> | ||
|
||
<button onclick="getLocation()">Set Map</button> | ||
<button onclick="resetMap()">Clean Map</button> | ||
|
||
<div id="mapholder"></div> | ||
|
||
<button onclick="getLocation2()">Example 2</button> | ||
<button onclick="getLocation3()">Example 3</button> | ||
|
||
{% endblock %} |
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
I think it's not working in https://alpha.semillasocial.org/webapp/geolocation because is mixing htttps and http.