in this javascript in the if statement 'if (data && data.length > 1' add a function to…
- User
in this javascript in the if statement 'if (data && data.length > 1' add a function to allow the user to add a marker to the map, - ' 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 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 }, 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();
const startingLocation = { lat: 51.540073, lng: -0.010874 }; // London Aquatics Center coordinates
function initMap() { const zoom = 8;
const map = new google.maps.Map(document.getElementById("map"), { center: startingLocation, zoom: zoom, mapId: "DEMO_MAP_ID", });
// 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 });
// Remove the click listener after adding a marker google.maps.event.removeListener(clickListener);
// Add functionality after clicking the map createSubmitButton(clickLocation); }
// Create a function to add the submit button function createSubmitButton(distance, clickLocation) { const buttonsDiv = document.getElementById("buttons");
// Check if the button already exists before creating a new one if (!document.getElementById("submit")) { const submitButton = document.createElement("button"); submitButton.id = "submit"; submitButton.textContent = ;
- Assistant
Within the if statement 'if (data && data.length > 1)', you can add a function to allow the user to add a marker to the map, as shown below:
javascript - User
I don't want to add a marker at the next street location I want to add a click event to the map which allows the user to click on the map to add a marker
- Assistant