【问题标题】:InfoWindow with google maps api带有谷歌地图 api 的信息窗口
【发布时间】:2013-02-12 12:26:56
【问题描述】:
如何在我的地图上显示两个信息窗口。
在我的代码中我只能打开一个 InfoWindow,但我会在我的地图上同时显示两个 InfoWindow 我能做什么。我的代码是:
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng( 38.736946, 35.310059), 6);
map.openInfoWindow(new GLatLng( 38.582526, 42.846680),
document.createTextNode("Van Gölü"));
}
}
【问题讨论】:
-
您正在使用 Google Maps API v2(尽管将您的问题标记为 API v3 - 我会正确地重新标记它)。 v2 API 已弃用,将在 May 2013 中停止工作。您应该将其重写为 API v3
-
-
标签:
google-maps-api-2
infowindow
【解决方案1】:
Google Maps API v2 原生 InfoWindow 仅支持每个地图一个。 Google Maps API v3 消除了该限制。
使用自定义 InfoWindow 或将您的应用程序迁移到 Google Maps API v3。
正如@duncan 所观察到的,Google Maps API v2 已于 2010 年 5 月 19 日正式弃用,并且在 2013 年 5 月 19 日之后将不再受支持。强烈建议不要对该 API 进行新的开发。
【解决方案2】:
此代码正在运行:
<!DOCTYPE html>
<html>
<head>
<META http-equiv=content-type content=text/html;charset=x-mac-turkish>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script src="js/jquery.js"></script>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=mykey&sensor=false">
</script>
<script type="text/javascript">
var map;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(39.078908,35.244141),
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
infoWindow = new google.maps.InfoWindow();
var windowLatLng = new google.maps.LatLng(38.668356,33.376465);
infoWindow.setOptions({
content: "Tuz Golu",
position: windowLatLng,
});
infoWindow.open(map);
infoWindow2 = new google.maps.InfoWindow();
var windowLatLng2 = new google.maps.LatLng(38.565348,42.868652);
infoWindow2.setOptions({
content: "Van Golu",
position: windowLatLng2,
});
infoWindow2.open(map);
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:65%; height:40%"></div>
</body>
</html>