0

我正在尝试实现这里 map(asp.net web app) 的新结构,但是,我看不到通过 javascript 传递位置信息和检索特定地址的功能,并将该信息与标记上的气泡粘贴在一起。

感谢任何建议。干杯

4

1 回答 1

0

我认为您正在寻找多个并发的反向地理编码请求。这样做没有问题,因为调用是异步的,您只需要记录哪些请求已完成,并在最后调用一次“完成后执行”的内容:

例如:

function concurrentSearch(map){
    // we will put our address markers into this container
    addressContainer = new nokia.maps.map.Container();
    managersFinished = 0;

    //Locations to be displayed
    latLngs= [[10,30], [-117.5, 15.3] ... etc];
    var  i = latLngs.length;

    while(i--) {
        nokia.places.search.manager.reverseGeocode({
            latitude: latLngs[i][0],
            longitude: latLngs[i][1],
            onComplete: processResults
        });
    }
}

使用回调函数,如图所示:

   function processResults(data, requestStatus) {
        if (requestStatus == "OK") {
            // if we are finished, we add a marker for the mapped position
            var marker = new nokia.maps.map.StandardMarker(data.location[0].position);
            marker.content = data.location[0].address.text; // add your content here
            addressContainer.objects.add(
                marker);
            //increment the counter to notify another manager has finished
            managersFinished++;
        } else if(requestStatus === "ERROR") {
            // we'll also increment in case of an error
            managersFinished++;
        }

        // if all managers are finished, we call the final function
        if(managersFinished === latLngs.length) {
            onAllManagersFinished();
        }
    }

最后的清理:

 function onAllManagersFinished() {
        //we get the bounding box of the container
        var bbox = addressContainer.getBoundingBox();

        // if the bounding box is null then there are no objects inside
        // meaning no markers have been added to it

        if (bbox != null) {
                // we have at least one address mapped
                // so we add the container and zoomTo it
                map.objects.add(addressContainer);
                map.zoomTo(bbox);
        } else {
                // otherwise we'll pop up an error message
                alert("There are no addresses to show :(");
        }
    }

此外,您可以在container上添加一个事件处理程序,它可以为您的所有位置打开信息气泡:

addressContainer.addListener(
    "click", 
    function (evt) { 
        infoBubbles.openBubble(evt.target.content, // content is your own stuff...
        evt.target.coordinate);
    }
);

如果您需要在反向地理编码时传递更多信息,您可以按照此处问题中描述的方式进行

可以在此处找到类似问题(多个地理编码请求)的解决方案。

于 2013-10-21T07:25:20.157 回答