首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在使用Google v3指南时裁剪v3

在使用Google v3指南时裁剪v3
EN

Stack Overflow用户
提问于 2011-12-16 13:53:02
回答 2查看 407关注 0票数 0

使用GMap APi v3,我使用“指导”服务为用户生成路由,但是一旦在地图上呈现该路由,我放置的目标信息就会被裁剪,因为映射集中在路由上,而不是目标上。

我如何告诉通用汽车公司:

  1. 会自动聚焦(或居中)在信息图上,而不是以不被裁剪的方式显示路径
  2. )(例如:使用信息图右上角的工具提示箭头而不是左下角的工具提示箭头,这将导致窗口出现在路由目标的右上角)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-12-17 11:11:04

我通过在.setCenter回调中使用directionsService ()(在接收到适当的响应之后)成功地完成了这一任务。但是,这只在使用超时时才有效。这可能不是最纯粹的解决办法,但这是我目前唯一可用的解决办法。

代码语言:javascript
复制
/* _x & _y are passed as coordinates */
var _latLng=new google.maps.LatLng(_x,_y);
directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        directionsRenderer.setDirections(response);
        window.setTimeout(function(){
            gmap.setCenter(_lagLng);
        }, 500);
    }
}

如果调用.setCenter()太早,则gmap仍然在构建,一旦完成,就会以路由为中心--从而将最后的命令重写为.setCenter() --但是,使用超时作为解决办法,调用将在构建映射和呈现路由之后进行。

票数 0
EN

Stack Overflow用户

发布于 2018-01-31 09:56:42

这是一个老问题,但这里有一个没有setTimeout的解决方案。您可以使用“tilesloaded”事件:

代码语言:javascript
复制
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(gmap);

directionsService.route(request, function(result, status) {
    if (status === 'OK') {
        directionsDisplay.setDirections(result);
        var listener = gmap.addListener('tilesloaded', function(){

            // add your centering code here
            // or open your infowindow here and maps will auto center like expected

            google.maps.event.removeListener(listener);

        });
    }else{
        console.warn('Error retreiving directions');
    }
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8535167

复制
相关文章

相似问题

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