Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何验证bing地图api密钥?_Javascript_Leaflet_Bing Api_Bing Maps - Fatal编程技术网

Javascript 如何验证bing地图api密钥?

Javascript 如何验证bing地图api密钥?,javascript,leaflet,bing-api,bing-maps,Javascript,Leaflet,Bing Api,Bing Maps,我正在使用bing地图插件的传单。 在传单使用bing maps api密钥之前,我如何验证该密钥 如果我允许这样使用无效密钥: var bing_key = "funTimeWithBingMaps" baseMapUrl = new L.BingLayer(bing_key) 然后bing地图报告: 传单Bing插件错误-获取元数据:访问被拒绝。您可能输入的凭据不正确,或者您可能无法访问请求的资源或操作 然后map.removeLayer(baseMapUrl)无法删除该层。您需要使用此网

我正在使用bing地图插件的传单。 在传单使用bing maps api密钥之前,我如何验证该密钥

如果我允许这样使用无效密钥:

var bing_key = "funTimeWithBingMaps"
baseMapUrl = new L.BingLayer(bing_key)
然后bing地图报告:

传单Bing插件错误-获取元数据:访问被拒绝。您可能输入的凭据不正确,或者您可能无法访问请求的资源或操作


然后
map.removeLayer(baseMapUrl)无法删除该层。

您需要使用此网站创建自己的密钥:


使用Microsoft帐户(又名Live ID)登录后,您将能够根据使用情况生成多个密钥。有关密钥类型的更多信息,请查看此处的MSDN:

这确实很难看,但这里有一个“解决方案”

var map, osm, bing, count_down = 50;

    function first_part()
    {
    map = new L.Map('map', {center: new L.LatLng(67.6755, 33.936), zoom: 10 });
    osm = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png');

    bing = new L.BingLayer("MyBingApiKeyGoesHere");
    setTimeout(function () { second_part(bing); }, 100);
    }

    function second_part(binz)
    {
        if (typeof(binz.meta.statusCode) == 'undefined') {
            count_down--;
            if (count_down == 0) {
                alert("abandon operation");
                return;
            }
            setTimeout(function () { second_part(binz); }, 100);
            return;
            }
        if (binz.meta.statusCode == 200) {
            alert("OK");
            map.addLayer(bing);
            map.addControl(new L.Control.Layers({'OSM':osm, "Bing":bing}, {}));
            }
        else {
            alert("WRONG: count_down: "+count_down+"  statusCode: "+binz.meta.statusCode);
            }
    }

    first_part();