1

编辑 4

一直以来,我一直在想这是标记的问题,它们不会被拖拽!现在我已经意识到,当地图显示在 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> 
4

3 回答 3

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 = new

于 2011-05-31T08:44:48.947 回答
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") ) ;
};
于 2011-06-04T04:52:04.740 回答
-1
google.maps.event.addListener (initialPointMarker, 'click', 
                                  function () { map.closeInfoWindow(); });

点击争论周围的单引号怎么样

于 2011-05-31T07:43:31.097 回答