LoginSignup
3
1

More than 5 years have passed since last update.

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

Last updated at Posted at 2018-04-17

記述内容

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']())
  });
});

参考

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1