In this javascript 'let streetLatitude; // Define streetLatitude globally let…
- User
In this javascript '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 totalPoints = 0; // Initialize total points variable
codefunction 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" } ] - Assistant
To display the points scored for each street view along with the lat, lng location, you can update the 'resultsDiv' content to include both the points scored and the lat, lng location. Here's how you can modify the code:
- Inside the loop where you are displaying the lat, lng location for each street view, update the content of 'resultsDiv' to include the points scored for that street view. You can use the following code snippet inside the loop:
javascriptconst streetPoints = `Street View ${i + 1}: Points = ${points}, Location = ${streetLatitude}, ${streetLongitude} <br>`; individualScores += streetPoints;- Update the finalScores variable with individual scores and total score:
javascriptconst finalScores = `${individualScores} Total Score: ${totalPoints}`;- Update the 'streetviewDiv' content with the finalScores:
javascript - User
I don't want to show the location for each street view
- Assistant
If you want to display only the points scored for each street view without showing the location (lat, lng) for each street view, you can modify the code as follows:
- Inside the loop where you are calculating the points scored for each street view, update the content of 'resultsDiv' to show only the points scored. You can use the following code snippet inside the loop:
javascriptconst streetPoints = `Street View ${i + 1}: Points = ${points} <br>`; individualScores += streetPoints;- Update the finalScores variable with individual scores and total score:
javascriptconst finalScores = `${individualScores} Total Score: ${totalPoints}`;- Update the 'streetviewDiv' content with the finalScores:
javascriptstreetviewDiv.innerHTML = finalScores;By making these changes, the 'resultsDiv' will now display only the points scored for each street view without showing the location (lat, lng) for each street view. The 'finalScores' string will include individual scores for each street view and the total score accumulated so far in the game.