首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >fitBounds和extend -出现在一个完全不同的地方

fitBounds和extend -出现在一个完全不同的地方
EN

Stack Overflow用户
提问于 2013-04-26 13:16:07
回答 1查看 145关注 0票数 0
代码语言:javascript
复制
var classBounds = new google.maps.LatLngBounds();
var query = "";

query = "SELECT 'ROAD_NUMBER', 'geometry' FROM [TABLE_ID HERE] WHERE 'ROAD_NUMBER' CONTAINS IGNORING CASE '" + searchString + "' AND 'LINK_NUMBER' CONTAINS '" +searchStringLinkNo + "'";
var encodedQuery = encodeURIComponent(query);

// Construct the URL
var url = ['https://www.googleapis.com/fusiontables/v1/query'];
url.push('?sql=' + encodedQuery);
url.push('&key=[key]');
url.push('&callback=?');


// Send the JSONP request using jQuery
$.ajax({
    url: url.join(''),
    dataType: 'jsonp',
    success: function (data){

        var rows = data['rows'];

        if(rows){

            var classRoadGeo1       = rows[0][1].geometry.coordinates;
            var classRoadGeo2       = rows[rows.length - 1][1].geometry.coordinates;
            var classRoadGeoStart   = classRoadGeo1[0];
            var classRoadGeoEnd     = classRoadGeo2[classRoadGeo2.length - 1];

            var startHolder = classRoadGeoStart.toString();
            var endHolder = classRoadGeoEnd.toString();

            var bound1 = startHolder.split(",");
            var bound2 = endHolder.split(",");

            var coordinate1 = new google.maps.LatLng(bound1[1], bound1[0]);
            var coordinate2 = new google.maps.LatLng(bound2[1], bound2[0]);

            alert(bound1);
            alert(bound2);

            classBounds.extend(coordinate1);
            classBounds.extend(coordinate2);                

        }
        else{

            alert("Unable to locate any counter/classifier stations for the current selection.");
        }
    }
}); 

map.fitBounds(classBounds);

}

所有的代码都在上面。我已经从融合表中取出几何图形,将其转换回字符串,并从中创建了一个LatLng对象。然而,当我运行fitBounds时,它会把我带到Papa New几内亚,而坐标实际上是澳大利亚悉尼的Kiama。我没有收到任何错误。你知道哪里可能出问题了吗?

EN

回答 1

Stack Overflow用户

发布于 2013-10-19 17:24:27

ajax请求是异步的,所以当调用map.fitBounds()时,边界还没有扩展。将最后一行"map.fitBounds(classBounds);“放在成功函数中if子句的末尾,它应该可以正常工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16229214

复制
相关文章

相似问题

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