Guerrilla!!

Take Photo

var map;
var marker;

// Inizializzazione della mappa
function initMap() {
map = new google.maps.Map(document.getElementById(‘map’), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
}

// Gestione del click del pulsante
document.getElementById(“camera-button”).addEventListener(“click”, function() {
// Accensione della telecamera
navigator.geolocation.getCurrentPosition(function(position) {
// Prendi la posizione attuale
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};

// crea un marker sulla mappa
marker = new google.maps.Marker({
position: pos,
map: map
});

//centra la mappa sulla posizione attuale
map.setCenter(pos);

// Scatta la foto usando la webcam
var video = document.createElement(“video”);
var canvas = document.createElement(“canvas”);
var ctx = canvas.getContext(“2d”);

navigator.mediaDevices.getUserMedia({ video: true }).then(function(stream) {
video.srcObject = stream;
video.play();

video.addEventListener(“canplay”, function() {
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
ctx.drawImage(video, 0, 0);

// Carica la foto sulla mappa
var image = canvas.toDataURL(“image/png”);
var infowindow = new google.maps.InfoWindow({
content: ‘
});
infowindow.open(map, marker);
stream.getTracks()[0].stop();
});
});
});

Pubblicità