谷歌地图API 3 -获取圆中心坐标



我有下一个代码用于获取多边形的坐标,但我想在画圆时获得中心坐标。

有人知道如何实现这一点吗?

致以最诚挚的问候,希望有人知道这件事。

function draw() { 
 if (drawingManager <= 0) then 
var drawingManager = new google.maps.drawing.DrawingManager({
  drawingMode: google.maps.drawing.OverlayType.POLYGON,
  drawingControl: true,
  drawingControlOptions: {
    position: google.maps.ControlPosition.TOP_CENTER,
    drawingModes: [
      google.maps.drawing.OverlayType.MARKER,
     google.maps.drawing.OverlayType.CIRCLE,
      google.maps.drawing.OverlayType.POLYGON,
     google.maps.drawing.OverlayType.POLYLINE,
     google.maps.drawing.OverlayType.RECTANGLE
    ]
  },
  markerOptions: {
    icon: 'images/beachflag.png'
  },
  polygonOptions: {
    fillColor: '#1E90FF',
    fillOpacity: 0.4,
    strokeWeight: 2,
    clickable: true,
    editable: true,
    zIndex: 1
  }
});

var coord_listener = google.maps.event.addListener(drawingManager, 'polygoncomplete', function (polygon) {
var coordinates = (polygon.getPath().getArray());

alert(coordinates);
PassPolygonToField(coordinates);
window.poly = polygon;
});

drawingManager.setMap(map);

} 
function PassPolygonToField(coordinates) {
//here I pass the coords to the form field and then I insert the form into a mysql database.
document.getElementById('myField').value = (coordinates);
}

在coord_listener:

之后添加以下代码
google.maps.event.addListener(drawingManager, 'circlecomplete', function(circle) {
  alert(circle.getCenter());
});

我遇到了同样的问题,我不得不使用:

const lat = circle.overlay.getCenter().lat()
const lng = circle.overlay.getCenter().lng()

相关内容

  • 没有找到相关文章

最新更新