我正在使用Google Maps API v3
,并且有几个链接到不同页面的地图标记。当onmouseover
状态栏不显示 url 时,但是当单击标记时,它会在状态栏中显示 url 加载文本。
似乎我的代码在某种程度上与状态栏冲突,或者您是否必须指定一个属性才能显示状态栏?这是我的代码:
function initialize(mapInfo)
{
// object literal for map options
var myOptions =
{
center: new google.maps.LatLng(30, 3), // coordinates for center of map
zoom: 2, // smaller number --> zoom out
mapTypeId: google.maps.MapTypeId.HYBRID // ROADMAP, SATELLITE, TERRAIN, or HYBRID
};
// note: if the id has a dash in its' name, map instantiation doesn't work!
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
// MAP MARKERS instantiated here
for(var i = 0; i < mapInfo.length; i++)
{
var link = mapInfo[i].link;
var name = mapInfo[i].name;
var lat = mapInfo[i].lat;
var lng = mapInfo[i].lng;
// object literal for each map marker
var marker = new google.maps.Marker(
{
url: link,
title: name,
position: new google.maps.LatLng(lat, lng),
map: map
});
// setting the link to each map marker here
setLink(marker);
// setting each map marker here
marker.setMap(map);
}
} // end of function initialize()
function setLink(mapMarker)
{
// event listener for marker links added to each marker
google.maps.event.addListener(mapMarker, "click", function()
{
window.location.href = mapMarker.url; // obtaining the url from the object literal
});
}
...我从 Ajax 获取对象文字 mapInfo(传递到函数初始化),用 JSON 解析——只是为了澄清 mapInfo 属性。
* ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * *编辑:** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ****
这是一个解决方案,只需将链接放入infowindow
:
// object literal for each map marker
var marker = new google.maps.Marker(
{
//url: link,
title: name,
content: "<a href = " + link + ">" + name + "</a>",
position: new google.maps.LatLng(lat, lng),
map: map
});
setWindow(map, marker);
function setWindow(map, mapMarker)
{
// event listener for marker links added to each marker
google.maps.event.addListener(mapMarker, "click", function()
{
var infowindow = new google.maps.InfoWindow(
{
content: mapMarker.content
});
infowindow.open(map, mapMarker);
});
}