in this javascript I am attempting to draw a polyline on a Google Map but it gives an…
- User
in this javascript I am attempting to draw a polyline on a Google Map but it gives an error - 'let streetLatitude; let streetLongitude; let marker; // Define marker globally to make it accessible across functions
function fetchStreetDetails(callback) { fetch("main.json") .then((response) => response.json()) .then((jsonData) => { const entryCount = jsonData.length; const streetDetails = jsonData[0];
code// Extract details const FeatureID = streetDetails.FeatureID; streetLatitude = streetDetails.StreetLatitude; streetLongitude = streetDetails.StreetLongitude; const streetHeading = streetDetails.StreetHeading; const streetPitch = streetDetails.StreetPitch; const streetPanoID = streetDetails.StreetPanoID; const StreetPoints = streetDetails.Points; console.log("FeatureID: " + FeatureID); 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("results"); numberoffeedsElement.textContent = `This is a ${entryCount} round game.`; callback(FeatureID); }) .catch((error) => console.error("Error fetching data: ", error));}
fetchStreetDetails((fetchedFeatureID) => { const paintingDiv = document.getElementById("painting"); const imageHTML = ''; paintingDiv.innerHTML = imageHTML; });
function initMap() { const mapOptions = { center: { lat: 21.382325, lng: -8.170154652 }, zoom: 3, };
const map = new google.maps.Map(document.getElementById("map"), mapOptions);
// Add a click event listener to the map const clickListener = map.addListener("click", (event) => { const clickLocation = event.latLng; // Get the latitude and longitude of the click
code - Assistant
The error you are encountering is likely due to the drawPolyline function not being called within the button event listener. Inside the click event listener for the "Submit" button, you have defined the lineCoordinates for the polyline, but you are missing the function call to draw the polyline on the map.
To fix this issue, you should call the drawPolyline function with the correct parameters (map) after defining the lineCoordinates for the polyline. Here is the updated code snippet with the necessary changes:
javascript - User
- Assistant
- User
- Assistant