使用Google API为广场设置完美的缩放级别 [英] Setting perfect zoom level for a Place with Google API

查看:130
本文介绍了使用Google API为广场设置完美的缩放级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Google地图应用中,用户可以搜索地点(使用自动完成),地图将以 map.setCenter(pos);

虽然这不会改变缩放级别,但必须使用 map.setZoom(x)手动完成。

在Google的地图中,缩放会自动重新调整以完美显示地点的边界,我该如何复制该行为?

解决方案

重复的@woelliJ发现几乎可以工作,但最终使用的是旧版本的API。它引导我走上了正确的轨道,并且最终找到了如何使它与新的API协同工作 - map.fitBounds(autocomplete.getPlace()。geometry.viewport);


In my Google Maps app the user can search for a place (using Autocomplete) and the map will be re-centered upon it with map.setCenter(pos);.

This does not change zoom level though, that must be done manually with map.setZoom(x).

In Google's map, zoom automatically readjusts to perfectly show the place's boundaries, how can I replicate that behavior?

解决方案

The duplicate @woelliJ found almost worked, but ended up using an old version of the API. It led me on the right track though, and I ended up finding how to make it work with the new API - map.fitBounds(autocomplete.getPlace().geometry.viewport);

这篇关于使用Google API为广场设置完美的缩放级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆