in this javascript when the 'game over' message is displayed I want the map bounds to be…
- User
in this javascript when the 'game over' message is displayed I want the map bounds to be set to fit all the markers that have been added to the map during the game - 'let streetLatitude; // Define streetLatitude globally let streetLongitude; // Define streetLongitude globally let marker; // Define marker globally to make it accessible across functions let data; // Declare data globally let currentIndex = 0; // Initialize index globally let totalScore = 0; // Initialize total points variable
function fetchStreetDetails() { fetch("main.json") .then((response) => response.json()) .then((jsonData) => { data = jsonData; // Store the data globally const entryCount = data.length; // data is already an array of objects const streetDetails = data[0]; // Extract street details streetLatitude = streetDetails.StreetLatitude; streetLongitude = streetDetails.StreetLongitude; streetHeading = streetDetails.StreetHeading; streetPitch = streetDetails.StreetPitch; streetPanoID = streetDetails.StreetPanoID; const StreetPoints = streetDetails.Points;
const panorama = new google.maps.StreetViewPanorama( document.getElementById("streetview"), { position: { lat: streetLatitude, lng: streetLongitude }, addressControl: false, pano: streetPanoID, heading: streetHeading, pitch: streetPitch, } );
console.log("Street Latitude: " + streetLatitude); console.log("Street Longitude: " + streetLongitude); console.log("Street Heading: " + streetHeading); console.log("Street Pitch: " + streetPitch); console.log("Street PanoID: " + streetPanoID); console.log("Street Location: " + StreetPoints);
// Update numberoffeeds div const numberoffeedsElement = document.getElementById("numberoffeeds"); numberoffeedsElement.textContent =
There are ${entryCount} questions in this game.; }) .catch((error) => console.error("Error fetching data: ", error)); }fetchStreetDetails(); function initMap() { const mapStyles = [ { featureType: "poi",
stylers: [ { visibility: "off", }, ], },
{ featureType: "poi.park",
stylers: [ { visibility: "off", }, ], }, { "featureType": "transit", "stylers": [ { "visibility": "off" } ] } ];
const mapOptions = { center: { lat: 21.382325, lng: -8.170154652 }, zoom: 3, styles: mapStyles, };
const map = new google.maps.Map( document.getElementById("map"), mapOptions );
// Function to add marker on click function addMarker(event) { const clickLocation = event.latLng; marker = new google.maps.Marker({ position: clickLocation, map: map, draggable: true, // Set draggable to true });
- Assistant
To set the map bounds to fit all the markers that have been added to the map during the game when the 'game over' message is displayed, you can modify the code as follows:
- Add a global array to store all the markers added to the map during the game:
javascriptlet markers = []; // Define a global array to store markers- When adding a marker to the map, push the marker to the
markersarray:
javascript