Javascript namitm:如何将各种信息传递给多个MQA.namitm.constructPOI回调?

Javascript namitm:如何将各种信息传递给多个MQA.namitm.constructPOI回调?,javascript,geocode,mapquest,Javascript,Geocode,Mapquest,我使用mapquest MQA.namignim模块在java脚本代码中对地址进行地理编码。 我想向回调函数MQA.namignm.constructPOI传递附加信息。 每个地理位置的信息都应该不同。 我使用javascript闭包将数据封装在每个回调函数中(这在google地理编码api中可以正常工作)。 namignim始终调用设置的最后一个回调函数。可以猜测,MQA.namignm.constructPOI是一个如何全局地址指针。 因此,我最终得到的所有标志和附加信息在地图上的所有位置看

我使用mapquest MQA.namignim模块在java脚本代码中对地址进行地理编码。 我想向回调函数MQA.namignm.constructPOI传递附加信息。
每个地理位置的信息都应该不同。
我使用javascript闭包将数据封装在每个回调函数中(这在google地理编码api中可以正常工作)。
namignim始终调用设置的最后一个回调函数。可以猜测,MQA.namignm.constructPOI是一个如何全局地址指针。
因此,我最终得到的所有标志和附加信息在地图上的所有位置看起来都是一样的。
有什么办法解决这个问题吗

我的代码如下所示:

<html>
<head>
    <script src="http://open.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js?key=xxxxxxx"></script>

    <script type="text/javascript">

        var flags = ['icons/flag_green.png', 'icons/flag_red.png'];

        var addressArr = [
     [', 49084 Osnabrueck, Germany','R','/trac/start/ticket/6677','Repair #6677'],
     [', 39599 Uchtspringe, Germany','R','/trac/start/ticket/6670','Repair #6670'],
     [', 17491 Greifswald, Germany','I','/trac/start/ticket/6625','Install #6625'],
     [', 37269 Eschwege, Germany','R','/trac/start/ticket/6620','Repair #6620'],
     [', 57076 Siegen, Germany','R','/trac/start/ticket/6602','Repair #6602'],
     [', 3109 St Poelten, Germany','I','/trac/start/ticket/6598','Install #6598'],
     [', 45884 Gelsenkirchen, Austria','R','/trac/start/ticket/6594','Repair #6594'],
     [', 48653 Coesfeld, Germany','R','/trac/start/ticket/6588','Repair #6588']
        ];

     function locationsCallback (location, osmLocation) {
            var type = location[1];
            var url = location[2];
            var title = location[3];
            var image = flags[0];
            if ('R' == type)
                  image = flags[1];

            /*Override the custom POI generation*/
            var lat = osmLocation.lat;
            var lng = osmLocation.lon;
            var p = new MQA.Poi({
               lat : lat,
               lng : lng
            });
            var customIcon = new MQA.Icon(image, 20, 29);
            p.setIcon(customIcon);

            /*Override the custom text populating the InfoWindow content*/
            p.setRolloverContent('<div style="font-size:14px;">' + title + '</div>');
            p.setInfoContentHTML('<div style="font-size:14px; width:180px;">' + url + '</div>');
            return p;
        };

        // define a function wich does the actual work of the callback and a func
        function setMarker (location) {
            MQA.Nominatim.constructPOI = function (osmLocation) {
                var callbackLoc = location;
                return locationsCallback(callbackLoc, osmLocation);
            };

            /*Executes a Nominatim search and adds the result to the map*/
            map.nominatimSearchAndAddLocation(location[0], null);
        }

       function setMarkers () {
           for (var i = 0; i < addressArr.length; i++) {
                var thisLoc = addressArr[i];
                // alert("Iteration: " + i + "   Geocode: " + location);

                /*This uses the MQA.withModule support to download and initialize the Nominatim support module. The constructPOI
                method is called to override the default behavior of constructing a POI.*/
                setMarker(thisLoc);
            }

       }
        function initialize() {

            /*Create an object for options*/
            var options = {
               elt : document.getElementById('map'), /*ID of element on the page where you want the map added*/
               zoom : 11, /*initial zoom level of map*/
               latLng: { lat:50.202250, lng:10.079730 },    /*center of the map is Bad Kissingen*/
               mtype:'osm',                                 /*map type (osm)*/
               bestFitMargin: 0,                            /*margin offset from the map viewport when applying a bestfit on shapes*/
               zoomOnDoubleClick: true                      /*zoom in when double-clicking on map*/
            };

            /*Construct an instance of MQA.TileMap with the options object*/
            window.map = new MQA.TileMap(options);

            /*This uses the MQA.withModule support to download and initialize the Nominatim support module. The constructPOI
              method is called to override the default behavior of constructing a POI.*/
            MQA.withModule('nominatim', setMarkers);
        };

        MQA.EventUtil.observe(window, 'load', initialize);

    </script>
</head>

<body>
    <div id='map' style='width:100%; height:750px;'></div>
</body>

var flags=['icons/flag_green.png'、'icons/flag_red.png'];
var addressArr=[
[49084德国奥斯纳布鲁克,'R','trac/start/TICKE/6677','Repair#6677'],
[39599 Uchtspringe,Germany','R','trac/start/ticket/6670','Repair#6670'],
[',17491德国格雷夫斯瓦尔德','I','trac/start/ticket/6625','Install#6625'],
[37269 Eschwege,Germany','R','trac/start/TICKE/6620','Repair#6620'],
[57076德国锡根,'R','trac/start/ticket/6602','Repair#6602'],
[3109 St Poelten,Germany','I','trac/start/ticket/6598','Install#6598'],
['45884 Gelsenkirchen,奥地利','R','trac/start/TICKE/6594','Repair#6594'],
[',48653科斯菲尔德,德国','R','trac/start/ticket/6588','Repair#6588']
];
函数位置ScalBack(位置,osmLocation){
变量类型=位置[1];
var url=位置[2];
var title=位置[3];
var image=flags[0];
如果('R'==类型)
图像=标志[1];
/*覆盖自定义POI生成*/
var lat=osmLocation.lat;
var lng=osmLocation.lon;
var p=新的MQA.Poi({
拉特:拉特,
液化天然气:液化天然气
});
var customIcon=新的MQA.Icon(图,20,29);
p、 设置图标(自定义图标);
/*覆盖填充信息窗口内容的自定义文本*/
p、 设置滚动内容(“”+标题+“”);
p、 setInfoContentHTML(“”+url+“”);
返回p;
};
//定义一个函数,该函数执行回调函数和func函数的实际工作
功能设置标记(位置){
MQA.m.constructPOI=函数(osmLocation){
var callbackLoc=位置;
返回位置scallback(callbackLoc、osmLocation);
};
/*执行命名搜索并将结果添加到映射*/
map.msearchandaddlocation(位置[0],空);
}
函数集标记(){
对于(变量i=0;i