【问题标题】:Why would Bing Maps' VEMap.Find be failing silently?为什么必应地图的 VEMap.Find 会默默地失败?
【发布时间】:2010-02-22 17:33:16
【问题描述】:

我正在对将 Bing 地图用于提议的应用程序进行一些研究,但我遇到了困难。一般的想法是我想显示我们在 X 距离内到某个位置的各种物品的位置。起点是美国地图,我们使用用户的点击来获取纬度/经度,并使用它来选择最近的城市。我们将把地图居中放置,然后为规定距离内的每个项目加载图钉。

在构建演示的过程中,我编写了以下内容。我遇到的问题是 plotZipcode 中对 landMap.Find 的调用静默失败。没有错误消息,并且landMap.Find 前后的控制台输出都按预期显示,但永远不会执行plotPushpin。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script charset="UTF-8" type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&mkt=en-us"></script>
<script type="text/javascript">
    var landMap = null;

    function getLatLong(evt) {
        var latLong = landMap.PixelToLatLong(new VEPixel(evt.mapX, evt.mapY));
        // This looks up the nearest city from the lat/long
        // and returns something like "EAGLE CREEK, IN"
        $.ajax({
            url: '/cfc/bing.cfc',
            data: {
                method: 'findCity',
                Latitude: latLong.Latitude,
                Longitude: latLong.Longitude
            },
            success: plotZipcode
        });
    }

    function plotPushpin(layer, results, places, expectMore, errorMessage) {
        console.log('Executing plotPushpin...');
        if (landMap && places && places.length >= 1) {
            var pushpin = new VEShape(VEShapeType.Pushpin, places[0].LatLong);
            pushpin.SetTitle('Available Repos Near '+places[0].Name);
            landMap.AddShape(pushpin);
        }
    }

    function plotZipcode(data, textStatus, XMLHttpRequest) {
        console.log('Executing plotZipcode...');
        if (landMap && data.length > 0) {
            console.log(data);
            landMap.Clear();
            console.log('Calling VEMap.Find...');
            landMap.Find(null, data, null, null, null, null, null, null, null, null, plotPushpin);
            //landMap.Find(null, data); // This doesn't work either.'
            console.log('Called VEMap.Find!');
        }
    }

    $(document).ready(function() {
        landMap = new VEMap('landLocation');
        landMap.LoadMap();
        landMap.ShowDisambiguationDialog(false);
        landMap.AttachEvent('onclick', getLatLong);
    });
</script>
<div id='landLocation' style="position:absolute; width:600px; height:400px;"></div>

特别令人沮丧的是,如果我使用 Firebug 手动执行以下操作,它的行为完全符合预期:

landMap.Find(null, "EAGLE CREEK, IN", null, null, null, null, null, null, null, null, plotPushpin);

任何关于 VEMap.Find 为何在我的 AJAX 回调中什么都不做的见解将不胜感激。

【问题讨论】:

标签: javascript ajax bing-maps bing


【解决方案1】:

问题是 Firefox 问题。出于某种原因,JQuery 文档就绪函数不喜欢使用对函数的引用来运行以加载地图。如果您将 mapload 方法放在正文 onload 事件中(html 或纯 javascript - 不是 jquery),它将起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多