Google Maps APIのDrawingManagerライブラリで、描画したpolygonの経緯度を取得する

記述内容

const defaultCenter = {
  lat: xxxxx
  lng: xxxxx,
}
const map = new google.maps.Map(document.getElementById('map'), {
  center: new window.google.maps.LatLng(defaultCenter.lat, defaultCenter.lng),
  zoom: 13
});
const drawingManager = new google.maps.drawing.DrawingManager({
  ...
  polygonOptions: {
    ...
    draggable: true,
    editable: true,
  }
});
drawingManager.setMap(map);

google.maps.event.addListener(drawingManager, 'polygoncomplete', function(polygon) {
  let polygonPath = polygon.getPath()
  console.log('polygonPath')
  console.log(polygonPath)
  polygonPath.forEach((value, ii)  => {
    console.log(ii + '個目')
    console.log(polygonPath.getAt(ii)['lat']())
    console.log(polygonPath.getAt(ii)['lng']())
  });
});

参考

Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.