GMap API 3单击触发链接标记

时间:2016-06-07 10:09:57

标签: javascript jquery html google-maps

我尝试为自动打开创建外部链接并从a缩放信息窗口但我收到此错误Uncaught ReferenceError: triggerClick is not defined

我知道它不是一个全局函数的原因,但是,如果我不在initMap(){}中,我的标记将不会被triggerclick函数知道。

我不知道该怎么办,你能帮助我吗?

这里是小提琴https://jsfiddle.net/9u2g4ue5/

我的触发功能:

    google.maps.event.addDomListener(window,'load',initMap);
    function triggerClick(i) {
    google.maps.event.trigger(markers[i], 'click');
    //map.getBounds();  
}

1 个答案:

答案 0 :(得分:1)

您也可以在另一个函数中声明一个全局函数。

javascript中的//Timer Variables var startTime = NSTimeInterval() var timer = NSTimer() var isTiming = Bool() var isPaused = Bool() func updatedTimer() { let currentTime = NSDate.timeIntervalSinceReferenceDate() var elapsedTime: NSTimeInterval = currentTime - startTime let minutes = UInt8(elapsedTime / 60.0) elapsedTime -= (NSTimeInterval(minutes) * 60) let seconds = UInt8(elapsedTime) elapsedTime -= NSTimeInterval(seconds) let strMinutes = String(format: "%02d", minutes) let strSeconds = String(format: "%02d", seconds) workoutTime.text = "\(strMinutes) : \(strSeconds)" } @IBAction func startButtonTapped(sender: AnyObject) { if !timer.valid { timer = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: #selector(TimedWorkoutViewController.updatedTimer), userInfo: nil, repeats: true) startTime = NSDate.timeIntervalSinceReferenceDate() } isTiming = true isPaused = false } @IBAction func pauseAndContinueButtonTapped(sender: AnyObject) { if isTiming == true && isPaused == false { timer.invalidate() //Stop the Timer isPaused = true //isPaused isTiming = false //Stopped Timing pauseButton.setTitle("RESUME", forState: UIControlState.Normal) //Set Button to Continue state print(startTime) } else if isTiming == false && isPaused == true { if !timer.valid { timer.invalidate() //timer = nil timer = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: #selector(TimedWorkoutViewController.updatedTimer), userInfo: nil, repeats: true) } isPaused = false isTiming = true pauseButton.setTitle("PAUSE", forState: UIControlState.Normal) //Set Button to Continue state } } 范围是global - 对象,只需将该函数指定为window的属性

window