是否可以从REST Service Bing地图获取城市名称?

时间:2018-08-29 07:15:00

标签: javascript maps bing city

我正在尝试制作一种可以检索地址,经度,纬度和城市名称的表格。

我有尝试的地址,经度和纬度,但卡在城市名称中

这是代码

<script type="text/javascript">
    $(document).ready(function() {
        $("#searchBox").autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: "http://dev.virtualearth.net/REST/v1/Locations",
                    dataType: "jsonp",
                    data: {
                        key: "----",
                        q: request.term
                    },
                    jsonp: "jsonp",
                    success: function(data) {
                        var result = data.resourceSets[0];
                        if (result) {
                            if (result.estimatedTotal > 0) {
                                response($.map(result.resources, function(item) {
                                    return {
                                        data: item,
                                        label: item.name + ' (' + item.address.countryRegion + ')',
                                        value: item.name
                                    }
                                }));
                            }
                        }
                    }
                });
            },
            minLength: 1,
            change: function(event, ui) {
                if (!ui.item)
                    $("#searchBox").val('');
            },
            select: function(event, ui) {
                displaySelectedItem(ui.item.data);
            }
        });
    });

    function displaySelectedItem(item) {
        $("#searchResult").empty().append('Data Result: ' + item.name).append(' (Latitude: ' + item.point.coordinates[0] + ' Longitude: ' + item.point.coordinates[1] + ' City Name: ' + item.cityname + ')');
    }
</script>

对于代码,我尝试使用' City Name: ' + item.cityname,但似乎无法打印当前的城市名称,输出为undefined

为我完成工作提供任何帮助。谢谢:)

0 个答案:

没有答案