Bug: event-click-latlng

オープン
#1,230 コメント 1 件 リアクション 0 件 担当者 1 名 GitHub で見る

@wangela がすでに取り組んでいます。

2022年8月26日 から。

評価

この issue はまだ評価されていません。

説明

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>
主要言語
TypeScript
スター
804
フォーク
826
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

googlemaps/js-samples のほかの issue

googlemaps/js-samples の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。