Javascript 如何在放置标记时获取多边形点

Javascript 如何在放置标记时获取多边形点,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我想在google地图中放置标记时获得多边形点。我的javascript代码如下所示 function draw_map_initialize() { var mapHeight = '400px'; // Set default height to Maps Containers $('#map-canvas').css('height', mapHeight); // Initialize map with markers(47.53187912201915, 7.7052223908

我想在google地图中放置标记时获得多边形点。我的javascript代码如下所示

function draw_map_initialize() {
 var mapHeight = '400px';
// Set default height to  Maps Containers
$('#map-canvas').css('height', mapHeight);

// Initialize map with markers(47.53187912201915, 7.705222390807307)
mymap = new GMaps({
    div: '#map-canvas',
    lat: 47.53187912201915,
    lng: 7.705222390807307,
    zoom: 20,
    zoomControl: true,
    mapTypeId: 'satellite'

});
map = mymap
drawingManager = new google.maps.drawing.DrawingManager({
        drawingControlOptions: {

        position: google.maps.ControlPosition.TOP_LEFT,
        drawingModes: [
            google.maps.drawing.OverlayType.MARKER,
            google.maps.drawing.OverlayType.POLYGON
        ]
    },
    //drawingMode: google.maps.drawing.OverlayType.POLYGON,
    markerOptions: {
        draggable: true                   
    },

    polylineOptions: {
        editable: true
    },
    map: map
});
}
function getAreasForCompany(idcompany) {
var area_values;
$.ajax({
    url: url_prefix + "getAreasForCompany",
    data: ({
        'idcompany': idcompany,
        'as_json': 1
    }),
    async: false,
    dataType: "json",
    success: function(data) {
        var result = {};
        var count = 1;
        var path = [];
        /* The for loop is to change the JSON data structure. New JSON structure to loop through the DB values to iterate the polygon. 
           The New JSON structure is to avoid naming restrictions of a polygon while storing  */
        for (var key in data) {
            obj = {
                'name': key,
                'coords': data[key]
            };
            result['area' + count++] = obj;
        }

        var company_area;
        map = mymap;
        /* Here we iterate the stored area points with the dynamically created result['area'+count++] */
        for (key in result) {
            company_area = map.drawPolygon({
                paths: result[key].coords,
                title: result[key].name,
                draggable: true,
                editable: true,
                strokeColor: 'black',
                strokeOpacity: 0.8,
                strokeWeight: 2,
                fillColor: '#FF0000',
                fillOpacity: 0.35,
                click: clickFun(this)
            });

       }
    },
    error: function(data, status, e) {
            alert(e);
        } // $("#zones").html(dataJson[i].coords);

});
}
我有另一种方法,在加载地图时绘制多边形,它看起来像这样

function draw_map_initialize() {
 var mapHeight = '400px';
// Set default height to  Maps Containers
$('#map-canvas').css('height', mapHeight);

// Initialize map with markers(47.53187912201915, 7.705222390807307)
mymap = new GMaps({
    div: '#map-canvas',
    lat: 47.53187912201915,
    lng: 7.705222390807307,
    zoom: 20,
    zoomControl: true,
    mapTypeId: 'satellite'

});
map = mymap
drawingManager = new google.maps.drawing.DrawingManager({
        drawingControlOptions: {

        position: google.maps.ControlPosition.TOP_LEFT,
        drawingModes: [
            google.maps.drawing.OverlayType.MARKER,
            google.maps.drawing.OverlayType.POLYGON
        ]
    },
    //drawingMode: google.maps.drawing.OverlayType.POLYGON,
    markerOptions: {
        draggable: true                   
    },

    polylineOptions: {
        editable: true
    },
    map: map
});
}
function getAreasForCompany(idcompany) {
var area_values;
$.ajax({
    url: url_prefix + "getAreasForCompany",
    data: ({
        'idcompany': idcompany,
        'as_json': 1
    }),
    async: false,
    dataType: "json",
    success: function(data) {
        var result = {};
        var count = 1;
        var path = [];
        /* The for loop is to change the JSON data structure. New JSON structure to loop through the DB values to iterate the polygon. 
           The New JSON structure is to avoid naming restrictions of a polygon while storing  */
        for (var key in data) {
            obj = {
                'name': key,
                'coords': data[key]
            };
            result['area' + count++] = obj;
        }

        var company_area;
        map = mymap;
        /* Here we iterate the stored area points with the dynamically created result['area'+count++] */
        for (key in result) {
            company_area = map.drawPolygon({
                paths: result[key].coords,
                title: result[key].name,
                draggable: true,
                editable: true,
                strokeColor: 'black',
                strokeOpacity: 0.8,
                strokeWeight: 2,
                fillColor: '#FF0000',
                fillOpacity: 0.35,
                click: clickFun(this)
            });

       }
    },
    error: function(data, status, e) {
            alert(e);
        } // $("#zones").html(dataJson[i].coords);

});
}
现在我想知道如何在标记放置在多边形上时立即获取多边形点,或者单击标记时是否可以获取多边形点


谢谢

绘制多边形的代码在哪里?@@ducan:我编辑了我的文章,在其中你可以看到绘制多边形的getAreasForCompany()。“类似这样的东西”是什么意思?请提供一份报告。
sac\u handler\u map
从哪里来?@@geocodezip:对不起,它的mymap不是sac\u handler\u map。它来自函数draw\u map\u initialize()