Javascript 基于seeach的谷歌地图动态定位

Javascript 基于seeach的谷歌地图动态定位,javascript,google-maps,Javascript,Google Maps,我使用Google.maps.map()创建了一个地图。 我有两个输入字段指定经度和纬度。我想在不发出GET请求的情况下将地图中心从当前位置更改为指定位置(基于lat和lng) 如何使用javascript实现这一点?将您的api密钥包含到google map api加载中,这将起作用 函数initMap(){ var centerCoordinates=new google.maps.LatLng(37.6,-95.665); var map=new google.maps.map(docu

我使用Google.maps.map()创建了一个地图。

我有两个输入字段指定经度和纬度。我想在不发出GET请求的情况下将地图中心从当前位置更改为指定位置(基于lat和lng)


如何使用javascript实现这一点?

将您的api密钥包含到google map api加载中,这将起作用

函数initMap(){
var centerCoordinates=new google.maps.LatLng(37.6,-95.665);
var map=new google.maps.map(document.getElementById('map'){
中心:中心坐标,
缩放:4
});
var card=document.getElementById('pac-card');
var input=document.getElementById('pac-input');
var infowindowContent=document.getElementById('infowindow-content');
map.controls[google.maps.ControlPosition.TOP\u RIGHT].push(卡片);
var autocomplete=new google.maps.places.autocomplete(输入);
var infowindow=new google.maps.infowindow();
setContent(infowindowContent);
var marker=new google.maps.marker({
地图:地图
});
autocomplete.addListener('place\u changed',function(){
document.getElementById(“位置错误”).style.display='none';
infowindow.close();
marker.setVisible(假);
var place=autocomplete.getPlace();
如果(!place.geometry){
document.getElementById(“位置错误”).style.display='inline block';
document.getElementById(“位置错误”).innerHTML=“无法在地图上找到”“+input.value+””;
回来
}
map.fitBounds(place.geometry.viewport);
标记器.设置位置(位置.几何.位置);
marker.setVisible(true);
infowindowContent.children['place-icon'].src=place.icon;
infowindowContent.children['place-name'].textContent=place.name;
infowindowContent.children['place-address'].textContent=input.value;
信息窗口。打开(地图、标记);
});
}

位置搜索


遵循以下链接中的指导:为了给您提供最佳解决方案,您需要提出一个您尝试过的代码,我们可以在其中进行分析并为您提供解决方案。