Interactive Infowindow Google Map V3

时间:2015-03-05 20:07:52

标签: javascript google-maps google-maps-api-3

这可能有一个非常简单的答案,但我无法让它发挥作用。

第一部分(不工作)。在infowindow内部:

    dataTitle = place.name;
    content += "<input type='button' value='Add this Spot' onclick='addToList("+place.geometry.location.lat()+","+place.geometry.location.lng()+",dataTitle);' >";

现场警报dataTitle工作正常,但是由于某种原因,dataTitle在addToList函数中为空。

第二部分(工作)。现在我在自定义信息窗口外面使用完全相同的东西,它工作得很好......

    dataTitle = $(this.content).find("div.gm-title").text();
    var link = $("<input type='button' value='Add this Spot' onclick='latLngSet(dataTitle)' >");

function latLngSet(title) {
    addToList(userLatitude,userLongitude,title);
}

纬度和经度都正确显示,只是标题在自定义信息窗口内显示为空白...

1 个答案:

答案 0 :(得分:0)

您在链接字符串中设置数据标题,如文本而非值。试试这个:

dataTitle = $(this.content).find("div.gm-title").text();
var link = $("<input type='button' value='Add this Spot' onclick='latLngSet("+ dataTitle +")' >");

function latLngSet(title) {
    addToList(userLatitude,userLongitude,title); }
相关问题