Javascript 将google map传递到html字符串中的函数会导致意外的标识符

Javascript 将google map传递到html字符串中的函数会导致意外的标识符,javascript,html,google-maps,Javascript,Html,Google Maps,我试图将google map作为参数传递到嵌入javascript中定义的html的函数调用中,如下所示: var html = "<div id='content'><a href='javascript:takeMeThere("+rectangle.getBounds().getCenter()+","+map+");'>"+rectangleId+"</a></div>"; 我试着不把地图作为一个参数,因为它是一个全局变量,我想它会很好地

我试图将google map作为参数传递到嵌入javascript中定义的html的函数调用中,如下所示:

var html = "<div id='content'><a href='javascript:takeMeThere("+rectangle.getBounds().getCenter()+","+map+");'>"+rectangleId+"</a></div>";
我试着不把地图作为一个参数,因为它是一个全局变量,我想它会很好地使用它,但它说setZoom不是一个函数,因为它根本无法识别地图,但它不会让我将它传递到我的函数中


有人知道我怎么把地图传过去吗?基本上,我希望信息气泡的内容(html字符串成为内容)是可点击的,当点击时,将使用户居中并放大该区域。

您需要使对函数的调用看起来像(其中
latLng
google.maps.latLng
对象,
map
google.maps.map
对象):

因此,HTML最终是(创建一个新的
google.maps.LatLng
对象,您可以传入对
矩形的引用,但它必须位于全局命名空间中):


function takeMeThere(rectCenter, map) {
    map.setZoom(17);
    map.panTo(rectCenter);
}
takeMeThere(latLng,map);
// implemented this way:
takeMeThere(new google.maps.LatLng(rectCenterLat, rectCenterLng),map);
var html = "<div id='content'><a href='javascript:takeMeThere(new google.maps.LatLng(" + rectangle.getBounds().getCenter().toUrlValue(6) + "),map);'>" + rectangleId + "</a></div>";