Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: event-click-latlng #1230

Open
rodrigojp2005 opened this issue Aug 26, 2022 · 1 comment
Open

Bug: event-click-latlng #1230

rodrigojp2005 opened this issue Aug 26, 2022 · 1 comment
Assignees

Comments

@rodrigojp2005
Copy link

Operating system

ubuntu 22.04

Browser Version

Chrome 104.0.5112.101 (oficial) 64 bits

How severe is the bug?

moderate

Bug description

function initMap() {
const myLatlng = { lat: -25.363, lng: 131.044 };

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);

});
}

declare global {
interface Window {
initMap: () => void;
}
}
window.initMap = initMap;
export {};

Steps to reproduce

Just run.

Console log output

I fixed it by commenting some parts below
 <script>
  function initMap() {
    const myLatlng = { lat: -25.363, lng: 131.044 };

  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);
  });
}
/*
declare global {
  interface Window {
    initMap: () => void;
  }
}*/
window.initMap = initMap;
//export {};
    </script>
@wangela
Copy link
Member

wangela commented Sep 13, 2022

Hi, please describe the issue. What is the expected behavior and what happens instead? If you are seeing an error message in the JavaScript console, share that as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants