Cordova leverages the HTML5 Geolocation capabilities with the following plugin: https://github.com/apache/cordova-plugin-geolocation Install it:
cordova plugin add cordova-plugin-geolocationExample:
if (navigator.geolocation) { navigator.geolocation.watchPosition(successCallback, errorCallback, {}); function successCallback(currentPosition) { var lat = currentPosition.coords.latitude; var lon = currentPosition.coords.longitude; console.log(lat + " " + lon); } function errorCallback(e) { console.log(e); } }
Basic Google Maps Usage (static maps)
var mapElem = document.getElementById('map'); mapElem.innerHTML = '<img src="http://maps.googleapis.com/maps/api/staticmap?markers=' + lat + ',' + long + '&zoom=20&size=300x300&sensor=false" />';
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=API_KEY"></script> var mapOptions = { center: { lat: -34.397, lng: 150.644}, zoom: 8 }; var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); <div id="map-canvas"></div>
What is the world's best camera?
Most Popular Cameras in the Flickr Community
Mobile phones have cameras built in that rival the best point and shoot cameras out there. Some even have optical zoom, built-in flashes and so on.
Not only capture but … (capture, storage, editing, viewing, sharing)
Impossible before, possible now:
Polaroid Android and Samsung Galaxy Camera
Say, Can You Make Phone Calls on That Camera?
What about?
The rise of the camera-phone
Everywhere you go, there are people with camera-phones - many of us record, document, and upload the minutae of our lives. But, ultimately, should we be doing it just because we can?
Why are we compelled to document everything? Are we missing anything in the process?
What about privacy? Activism/Protest? Surveillance?
Illicit photos?
Vancouver Riot Identify Suspects
Arab Spring
How to Remove Location Information from Mobile Photo
<img src="img/scene.jpg">You'll probably also want to style it
<style> #mypicture { width: 90%; height: auto; } </style> <img id="mypicture" src="img/scene.jpg">
phonegap cordova plugin add cordova-plugin-cameraThen you can use it in your JavaScript:
function onDeviceReady() { alert("Device Ready"); takePicture(); } function takePicture() { navigator.camera.getPicture(onSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI }); } function onSuccess(imageData) { var image = document.getElementById('mypicture'); //image.src = "data:image/jpeg;base64," + imageData; console.log(imageData); image.src = imageData; } function onFail(message) { alert('Failed because: ' + message); }
destinationType : Camera.DestinationType.DATA_URLto get a data url instead of a file path. You can use
sourceType: Camera.PictureSourceType.PHOTOLIBRARYto get a picture from the library/gallery rather than from the camera.
var canvas = document.getElementById("canvas_id"); var ctx = canvas.getContext("2d"); var image = new Image(); // This should be the data url of the image you just captured image.src = "data:image/jpg;base64,iVBORw0KGgoAAAANSUhEUgAA..."; image.onload = function() { ctx.drawImage(image, 0, 0); };
phonegap cordova plugin add cordova-plugin-media-captureHere is some simple JavaScript which illustrates it's use:
function onDeviceReady() { alert("Device Ready"); // start video capture navigator.device.capture.captureVideo(captureSuccess, captureError, {limit:1}); } function captureSuccess(mediaFiles) { // An array of media files is returned. In this case, only interested in the first one. console.log(mediaFiles[0].fullPath); // Use JQuery to add a "src" attribute to the video tag and play it. $("#myvideo").attr("src", mediaFiles[0].fullPath).get(0).play(); } function captureError(error) { navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error'); }
phonegap cordova plugin add https://github.com/EddyVerbruggen/VideoCapturePlus-PhoneGap-Plugin.git phonegap cordova prepareImport it into your index.html (don't forget to copy the file):
<script type="text/javascript" src="js/VideoCapturePlus.js"></script>Here is some JavaScript (requires three divs, with ids "video_container", "video_meta_container", and "video_meta_container2"):
function captureSuccess(mediaFiles) { mediaFile = mediaFiles[0]; console.log(mediaFile.fullPath); mediaFile.getFormatData(getFormatDataSuccess, getFormatDataError); // This time we'll create a video element the normal way var vid = document.createElement('video'); vid.id = "theVideo"; vid.width = "240"; vid.height = "160"; vid.controls = "controls"; var source_vid = document.createElement('source'); source_vid.id = "theSource"; source_vid.src = mediaFile.fullPath; vid.appendChild(source_vid); document.getElementById('video_container').innerHTML = ''; document.getElementById('video_container').appendChild(vid); document.getElementById('video_meta_container2').innerHTML = parseInt(mediaFile.size / 1000) + 'KB ' + mediaFile.type; } function getFormatDataSuccess(mediaFileData) { document.getElementById('video_meta_container').innerHTML = mediaFileData.duration + ' seconds, ' + mediaFileData.width + ' x ' + mediaFileData.height; } function getFormatDataError(error) { alert('A Format Data Error occurred during getFormatData: ' + error.code); } function captureError(error) { navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error'); }
function uploadFile(mediaFile) { var ft = new FileTransfer(), path = mediaFile.fullPath, name = mediaFile.name; ft.upload(path, "http://www.yourdomain.com/path/to/uploader.php", function(result) { console.log('Upload success: ' + result.responseCode); console.log(result.bytesSent + ' bytes sent'); }, function(error) { console.log('Error uploading file ' + path + ': ' + error.code); }, { fileName: name, fileKey: 'bytes', mimeType: 'video/3gpp' }); }