1

EDIT 4地圖不上點擊鼠標與谷歌地圖API V3響應和QWebView

所有這一切,而我就在想,這是標記問題,即他們沒有得到拖! 現在我已經意識到,當它在Qt小部件中顯示時,沒有鼠標點擊在地圖上工作。

下面的代碼,我粘貼在一個HTML文件,並通過Firefox打開,這完美無缺地工作!並且當我點擊QtWidget上的地圖時,它也沒有反應:rolleyes:

任何人都可以爲我確認這一點或告訴我我在做什麼錯誤?

谷歌地圖JavaScript API示例

<script type="text/javascript"> 

var map;  
var latlng   = new google.maps.LatLng (34.7607233, -117.0107599); 

var directionsDisplay = new google.maps.DirectionsRenderer();; 
var directionsService = new google.maps.DirectionsService(); 

var pointsArray  = new Array(); 
var arrayToBeReturned = new Array(); 

function initialize() 
{ 
    var myOptions = 
    { 
     zoom:8, 
     center:latlng, 
     mapTypeId:google.maps.MapTypeId.ROADMAP 
    }; 

    map = new google.maps.Map (document.getElementById ("map"), myOptions); 
    directionsDisplay.setMap (map); 

    google.maps.event.addListener (map, "click", function() 
         { 
          alert("You clicked the map."); 
         }); 
    } 

</script> 
</head> 
<body onload="initialize()" topmargin="0" leftmargin="0"> 
<div id="map" style="width: 341px; height: 271px"></div> 
<div id="directionsPanel" style="float:right;width:30%;height 100%"></div> 
</body> 
</html> 

回答

1

找到了解決辦法:

添加這個類的源文件中的你在哪裏「裝「Qt小部件中的HTML文件(包含Javascript API)。

class myWebPage : public QWebPage 
{ 
    virtual QString userAgentForUrl(const QUrl& url) const { 
     return "Chrome/1.0"; 
    } 
}; 

然後在同一個源文件在自己的類,添加setPage函數調用,如下圖所示,看到了魔術發生!

MainScreen::MainScreen(QWidget *parent):QWidget(parent) 
{ 
     ... 
    ***map->setPage (new myWebPage());*** 
    map->load (QUrl("./index.html")) ; 
}; 
+0

雖然使用Google API ** V2 **的人不需要此代碼,因爲API ** V2 **不存在此問題。 – 2011-06-04 07:42:45

-1
google.maps.event.addListener (initialPointMarker, 'click', 
            function() { map.closeInfoWindow(); }); 

如何圍繞點擊arguement單引號

1

您正在尋找在錯誤的地方,事件:)在引用每個對象都有自己的事件。你可以在這裏看到那些爲標誌:

[http://code.google.com/apis/maps/documentation/javascript/reference.html#Marker][1]

我已經使用了dragend事件很多次,並且工作順利。

做的代碼,它可能是:

var map = new google.maps.Map(document.getElementById("map"), myOptions); 

    var marker = new google.maps.Marker({ 
     position: latlng, 
     map: map, 
     draggable: true 
    }); 

    google.maps.event.addListener(marker, 'dragend', function() { 
     document.getElementById("txtLatitude").value = marker.getPosition().lat(); 
     document.getElementById("txtLongitude").value = marker.getPosition().lng(); 
    }); 

[1]:http://code.google.com/apis/maps/documentation/javascript/reference.html#Markermap =新

+0

謝謝,我會嘗試並報告回來。 – 2011-05-31 08:48:21

+0

查看OP中的編輯:(它仍然不起作用,我錯過了什麼? – 2011-05-31 10:29:42

+0

如果這是你使用的代碼,你不會在你的事件中調用任何代碼,我編輯了我的答案以反映你可以做什麼:)如果這仍然不起作用,請說明是否出現錯誤。 – 2011-05-31 10:50:28