这是我当前的代码:
$scope.search = function(){
Request.googleAPI($scope.searchForm).then(function(data){
console.log("Search result: ")
console.log(data)
var actualZoom = map.getView().getZoom();
console.log("Zoom level: " + actualZoom)
var point = [data.data.results[0].geometry.location.lng, data.data.results[0].geometry.location.lat];
var size = /** @type {ol.Size} */ (map.getSize());
view.centerOn(ol.proj.transform(point, 'EPSG:4326', 'EPSG:3857'), size, [size[0]/2, size[1]/2]);
/*
map.setView(new ol.View({
projection: 'EPSG:4326',
center: [long, lat], //long,lat
zoom: actualZoom
}));
*/
})
}
我试过使用底部评论的内容(建议在 SO 上)。我将其调整为仅使用“缩放”,但它会使我的地图变白。
Google Maps 请求包含几何点位置(lat/lng),还包含边界框,它应该确定缩放级别。如何使用此边界框正确更新我的地图?
如果您需要查看更多代码,这里是我正在使用的完整脚本。