首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >微软必应地图v7搜索管理器GeoCode errorCallBack

微软必应地图v7搜索管理器GeoCode errorCallBack
EN

Stack Overflow用户
提问于 2017-08-09 02:21:36
回答 1查看 453关注 0票数 0

该问题发生在页面刷新期间,然后浏览器最小化或其带有地图的选项卡处于非活动状态。然后搜索管理器地理编码功能落入errorCallback。如果包含地图的页面处于活动状态(可见),则一切正常。

我检查了errorCallback函数中的e.request对象,它包含正确的"where“参数,但没有纬度和经度,也没有关于错误的任何信息。

该问题可在Chrome和IE浏览器中重现。

HTML:<div id="map" class="map" style="height:270px; width:100%"></div>

JavaScript:

代码语言:javascript
复制
<script type="text/javascript" src="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&s=1"></script>

<script type="text/javascript">

    // global variables
    var apiKey = 'API_KEY_HIDDEN',
        map,
        searchManager;

    // sample data
    var siteData = [
        {"Name":"Starbucks","Address":"8400 SW Nimbus Ave 120","City":"Beaverton","State":"OR","Zip":"97008","Latitude":0,"Longitude":0},
        {"Name":"Subway","Address":"12160 SW Scholls Ferry Rd","City":"Tigard","State":"OR","Zip":"97223","Latitude":0,"Longitude":0}
    ];

    $(document).ready(function () {
        GetMap();
        setTimeout(function() { location.reload(); }, 60000);
    });

    function GetMap() {    

        // initialize the map
        map = new Microsoft.Maps.Map(document.getElementById('map'), {
            credentials: apiKey,
            mapTypeId: Microsoft.Maps.MapTypeId.road,
            zoom: 1
        });

        // load search module
        Microsoft.Maps.loadModule('Microsoft.Maps.Search', {
            callback: function () {
                searchManager = new Microsoft.Maps.Search.SearchManager(map);
                $.each(siteData, function(index, clientSite) {
                    GeoCodeQuery(clientSite);
                });
            }
        });
    }

    function GeoCodeQuery(clientSite) {

        // set search parameters
        var searchRequest = {
            where: clientSite.Address + ', ' + clientSite.City + ', ' + clientSite.State + ' ' + clientSite.Zip,
            callback: function (data) {
                if (data && data.results && data.results.length > 0) {
                    clientSite.Latitude = data.results[0].location.latitude;
                    clientSite.Longitude = data.results[0].location.longitude;
                }
                else {
                    console.log('No results.');
                }
            },
            errorCallback: function (e) {
                console.log('Search error.');
            }
        };

        // make the geocode request
        searchManager.geocode(searchRequest);           
    }

</script>
EN

回答 1

Stack Overflow用户

发布于 2017-08-09 14:11:23

几个问题;

  • 您的where参数后缺少逗号。这将使searchRequest成为无效的JSON对象。修复此问题会导致对第一个地址进行正确的地理编码。第二个是抛出错误,这可能是由于许多原因,最有可能的是下一个点。
  • 必应地图V7控件已于6月份退役,并将很快关闭。它的一些后端服务已经被关闭,因此它将会出现问题。你应该使用必应地图V8,它在一年前就取代了V7。您可以在此处找到迁移指南:https://social.technet.microsoft.com/wiki/contents/articles/34563.bing-maps-v7-to-v8-migration-guide.aspx
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45575461

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档