2013-02-12 95 views
0

如何在我的地圖上顯示兩個Infowindow。InfoWindow與Google地圖apı

在我的代碼中我只能打開一個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ü")); 
} 
} 
+0

您使用谷歌地圖API V2(儘管標記你的問題的API v3的 - 我會正確地重新打吧)。 v2 API已棄用,並將於[2013年5月]停止工作(https://developers.google.com/maps/documentation/javascript/v2/)。您應該將其重寫爲API v3 – duncan 2013-02-12 13:44:32

+0

如何使用apı版本3 – 2013-02-12 14:17:19

+0

[google mapsapı處理html和javascript]的可能重複(http://stackoverflow.com/questions/14829843/google-maps-api-processing-與-html和JavaScript) – geocodezip 2013-02-12 14:35:11

回答

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中的新開發強烈不鼓勵。

+0

好的。如何將我的項目轉換爲Apıver3 – 2013-02-12 14:02:17

+1

這取決於上面的[link](https://developers.google.com/maps/documentation/javascript/v2/reference):[將Google Maps JavaScript應用升級到v3] (https://developers.google.com/maps/articles/v2tov3) – geocodezip 2013-02-12 14:17:13

+0

您的項目是什麼樣子?您發佈的代碼只會嘗試一次infowindow。 – geocodezip 2013-02-13 06:42:04

0

此代碼工作:

<!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>