javascript - mapkit.js:如何实现注解选中和取消选中时的放大缩小
问题描述
我正在使用 JavaScript 为我的网站实现苹果地图。我的网站显示了许多附近的酒店以进行搜索位置查询。所以如果你搜索金门大桥,它会绘制出近60-70家附近的酒店,用户可以点击获取特定酒店的信息。我想要实现的是当用户单击注释时,地图应该放大到该注释,一旦用户返回,这应该缩小到以前的缩放级别,以便所有标记都应该可见。
此外,对于登陆页面,我已将区域设置为旧金山,但我的地图设置在中东。
这是我的代码
$(document).ready(function){
//this is the first code which is landing me in middle east
map = new mapkit.Map("map");
var coord = new mapkit.Coordinate(37.3382082,-121.8863286);
var zoomlevel = new mapkit.CoordinateSpan(.001);
var zoomOut = new mapkit.CoordinateSpan(0.004);
var region = new mapkit.CoordinateRegion(coord, zoomlevel);
map.setRegionAnimated(region);
//when click on annotaion
var coordinate = data.coordinate; //data would be hotel data
var region = new mapkit.CoordinateRegion(coordinate, zoomlevel);
map.setRegionAnimated(region);
// when going back
var selectedCordinate = map.selectedAnnotation.coordinate;
var region = new mapkit.CoordinateRegion(selectedCordinate, zoomOut);
map.setRegionAnimated(region);
});
放大正在发生,但是当我将其设置为 0.004 时缩小时,每个区域的行为都不同。如果我在地图上有很多标记,那么它的行为会有所不同,但如果我的标记较少,那么它的行为就会完全不同。我想要一种动态解决方案,以便它适用于所有类型的区域。
解决方案
推荐阅读
- python - 非布尔变量的布尔运算
- javascript - 为什么 null 在 while 循环中不能正常工作?
- python - 附加功能似乎在 Python 中不起作用
- database - 在 oracle 中创建表时出现错误。可能是什么错误?
- javascript - 使用 Cypress 无法在 Web 应用程序上单击开始按钮
- android - Windows Azure VM 中的 Android 模拟器黑屏
- c# - 具有空值的 Newtonsoft.Json.JsonConvert.DeserializeObject 问题
- openssl - 将 aws 导出的私钥转换为 pkcs12 时出错:无法加载私钥
- sql - 在同一个表中连接由分隔符分隔的列
- nginx - 使用 SSL 和其他服务器在 NGINX 后面代理 COTURN