Google maps 发送多个地址时在Google地图上设置视口

Google maps 发送多个地址时在Google地图上设置视口,google-maps,Google Maps,我有代码,我想发送几个地址到谷歌地图。但是,由于我正在进行一系列地理编码,如何使视口至少居中并在组上正确缩放 function doBatchGeocodeAndSearch() { $('#loading').css('visibility', 'visible'); var lines = $('#styled').val().split('\n'); for(var i = 0;i < lines.length;i++){ geocoder.geocode( { 'add

我有代码,我想发送几个地址到谷歌地图。但是,由于我正在进行一系列地理编码,如何使视口至少居中并在组上正确缩放

function doBatchGeocodeAndSearch() {
$('#loading').css('visibility', 'visible');

var lines = $('#styled').val().split('\n');

for(var i = 0;i < lines.length;i++){
    geocoder.geocode( { 'address': lines[i]}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
        map.fitBounds(results[0].geometry.viewport); 
        // map.setCenter(bounds.getCenter(),
        // map.getBoundsZoomLevel(bounds));
        map.setCenter(results[0].geometry.location);
函数doBatchGeocodeAndSearch(){
$('加载').css('可见性','可见');
变量行=$('#styled').val().split('\n');
对于(变量i=0;i
删除map.setCenter调用。对map.fitBounds的最后一次调用将显示所有标记,如果只有一个标记,将放大到非常近的位置,可能需要特别处理

var bounds = new google.maps.LatLngBounds();
for(var i = 0;i < lines.length;i++){
  geocoder.geocode( { 'address': lines[i]}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      bounds.extend(results[0].geometry.location);
      map.fitBounds(bounds);
var-bounds=new google.maps.LatLngBounds();
对于(变量i=0;i