javascript - 如何修复不是 LatLng 或 LatLngLiteral:不是对象问题 - Google 地图
问题描述
此功能的想法是,当用户输入一个位置时,我们在该位置添加一个标记并平移所述标记并放大该标记的位置。然而,所有这些工作都相对良好。它给了我这个错误“ Uncaught Kc {message:”not a LatLng or LatLngLiteral: not an Object”, name: “InvalidValueError”。”
if(map.getZoom() == 2) {
map.setCenter({lat:data.address_lat2, lng:data.address_lng2});
map.panTo(marker.position);
smoothZoom(map, 11, map.getZoom());
var location = new google.maps.LatLng({lat:data.address_lat2, lng:data.address_lng2});
var bounds = new google.maps.LatLngBounds();
bounds.extend(location.position);
map.fitBounds(bounds);
}
这是我的 smoothZoom 功能
function smoothZoom (map, max, cnt) {
if (cnt >= max) {
return;
} else {
z = google.maps.event.addListener(map, 'zoom_changed', function(event){
google.maps.event.removeListener(z);
smoothZoom(map, max, cnt + 1);
});
setTimeout(function(){map.setZoom(cnt)}, 150);
}
}
解决方案
原来这行代码 bounds.extend(location.position); 应该是 bounds.extend({lat:data.address_lat2,lng:data.address_lng2});
推荐阅读
- visual-studio - Visual Studio 的 UnderWare Brief 命令仿真与 Emacs 和普通 Edit 相比如何?
- python - pandas 将集合的 DataFrame 转换为字典的 DataFrame 的方法,其中值在其他 DataFrame 的相应单元格中
- rust - 如何在 Rust 中实现运行时选择的策略?
- python - Python重复命名
- python - python BeautifulSoup 和 Requests 的问题
- python - 在 Python 中过滤 JSON 元素不起作用
- node.js - 通过 chrome 终端将 Access-Control-Allow-Origin 添加到 fetch 方法的标题中
- c# - 从另一台 PC 访问 C# SQL 数据库
- mysql - 在 sequelize bulkCreate 时间戳不更新
- php - 使用 Nginx 托管超过 1 个简单的 wordpress 站点时出现重复的上游错误