Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps 如何在google maps事件中访问此对象_Google Maps_Google Maps Api 3 - Fatal编程技术网

Google maps 如何在google maps事件中访问此对象

Google maps 如何在google maps事件中访问此对象,google-maps,google-maps-api-3,Google Maps,Google Maps Api 3,我正在从谷歌地图V2升级到V3。我被这个功能卡住了。在添加事件侦听器时,我必须将this对象传递给函数。我无法解释这一点 例如: Namespace.mapWrapper.prototype.enableZoneDraw = function(callback) { if (!this.isDrawing) { //this.clickListener = GEvent.bind(this.api, 'click', this, this.toggleZoneDraw);

我正在从谷歌地图V2升级到V3。我被这个功能卡住了。在添加事件侦听器时,我必须将this对象传递给函数。我无法解释这一点

例如:

Namespace.mapWrapper.prototype.enableZoneDraw = function(callback) {
    if (!this.isDrawing) {
        //this.clickListener = GEvent.bind(this.api, 'click', this, this.toggleZoneDraw);
        this.clickListener = google.maps.event.addListener(this.api, 'click', this.toggleZoneDraw); //this.api is map object
        if (callback) {
            this.drawEndCallback = callback;
        }
    }
}

Namespace.mapWrapper.prototype.toggleZoneDraw = function(event) {
    // Start drawing zone
    if (!this.isDrawing) {
        if(event.latLng){
            this.zoneCenter = event.latLng;
            this.isDrawing = true;
            this.drawListener = google.maps.event.addListener(this.api, 'mousemove', another_function);
        }
    } else {
        this.isDrawing = false;
        google.maps.event.removeListener(this.drawListener);
        google.maps.event.removeListener(this.clickListener);
    }
}
我想在toggleZoneDraw中访问更多enableZoneDraw对象,但在toggleZoneDraw中,如果我访问此对象,它将引用新对象

请帮忙

谢谢

Namespace.mapWrapper.prototype.enableZoneDraw = function(callback) {
    if (!this.isDrawing) {
        //create a reference to the current this object
        var obj = this;
        this.clickListener = google.maps.event.addListener(
            this.api, //this.api is map object
            'click',
            //use a closure to maintain our reference to this object
            function (evt) {
                obj.toggleZoneDraw(evt);
            }
        );
        if (callback) {
            this.drawEndCallback = callback;
        }
    }
}