Answer to Question #257230 in HTML/JavaScript Web Application for Yami

Question #257230

//Add a function in the event listener that post the LATlng to a python file

function initMap() {

 const myLatlng = { lat: -33., lng: 18 };

 const map = new google.maps.Map(document.getElementById("map"), {

  zoom: 4,

  center: myLatlng,

 });

 // Create the initial InfoWindow.

 let infoWindow = new google.maps.InfoWindow({

  content: "Click the map to get Lat/Lng!",

  position: myLatlng,

 });


 infoWindow.open(map);

 // Configure the click listener.

 map.addListener("click", (mapsMouseEvent) => {

  // Close the current InfoWindow.

  infoWindow.close();

  // Create a new InfoWindow.

  infoWindow = new google.maps.InfoWindow({

   position: mapsMouseEvent.latLng,

  });

  infoWindow.setContent(

   JSON.stringify(mapsMouseEvent.latLng.toJSON(), null, 2)

  );

  infoWindow.open(map);

 });

}


1
Expert's answer
2021-10-27T00:26:09-0400
function initMap() {
  const myLatlng = { lat: -33, lng: 18 };

  const map = new google.maps.Map(document.getElementById("map")!, {
    zoom: 4,
    center: myLatlng,
  });

  // Create the initial InfoWindow.
  let infoWindow = new google.maps.InfoWindow({
    content: "Click the map to get Lat/Lng!",
    position: myLatlng,
  });

  infoWindow.open(map);

  // Configure the click listener.
  map.addListener("click", (mapsMouseEvent) => {
    // Close the current InfoWindow.
    infoWindow.close();

    // Create a new InfoWindow.
    infoWindow = new google.maps.InfoWindow({
      position: mapsMouseEvent.latLng,
    });
    infoWindow.setContent(
      JSON.stringify(mapsMouseEvent.latLng.toJSON(), null, 2)
    );
    infoWindow.open(map);
  });
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS