Bug: event-click-latlng

Đang mở
#1,230 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

@wangela đang làm issue này rồi.

Từ ngày 26/8/2022.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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>
Ngôn ngữ chính
TypeScript
Star
804
Fork
826
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của googlemaps/js-samples

Tất cả issue của googlemaps/js-samples

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.