Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用邮政编码地理编码的Google Maps API V3多标记_Javascript_Google Maps_Google Maps Api 3_Google Geocoder_Geocode - Fatal编程技术网

Javascript 使用邮政编码地理编码的Google Maps API V3多标记

Javascript 使用邮政编码地理编码的Google Maps API V3多标记,javascript,google-maps,google-maps-api-3,google-geocoder,geocode,Javascript,Google Maps,Google Maps Api 3,Google Geocoder,Geocode,我目前正试图在我的网页上制作一个多标记的谷歌地图,但试图从邮政编码中获取每个标记的位置。我已经找到了标记代码和邮政编码地理代码,但我似乎找不到一种方法将它们粘在一起 我拥有的多标记代码: <script type="text/javascript"> var locations = [ ['Chester', 53.183497, -2.890605, 3, 'https://www.google.co.uk'], ['Manchester', 53.474103,

我目前正试图在我的网页上制作一个多标记的谷歌地图,但试图从邮政编码中获取每个标记的位置。我已经找到了标记代码和邮政编码地理代码,但我似乎找不到一种方法将它们粘在一起

我拥有的多标记代码:

  <script type="text/javascript">
  var locations = [
  ['Chester', 53.183497, -2.890605, 3, 'https://www.google.co.uk'],
  ['Manchester', 53.474103, -2.243593, 2, 'https://www.google.co.uk'],
  ['Liverpool', 53.421206, -2.945146, 1, 'https://www.google.co.uk/']
  ];


var map = new google.maps.Map(document.getElementById('map'), {
  zoom: 9,
  center: new google.maps.LatLng(53.381021, -2.608138),
  mapTypeId: google.maps.MapTypeId.TERRAIN,

});

var infowindow = new google.maps.InfoWindow();

var marker, i;

for (i = 0; i < locations.length; i++) {  
  marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    url: locations[i][4],
    map: map
  });

    google.maps.event.addListener(marker, 'dblclick', function() {
            window.location.href = this.url;
        });

  google.maps.event.addListener(marker, 'click', (function(marker, i) {
    return function() {
      infowindow.setContent(locations[i][0]);
      infowindow.open(map, marker);
    }
  })(marker, i));
}
</script>
  <html>
  <head>
  <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  <script type="text/javascript"></script>
  </head>
  <body onload="initialize()">
  <div align="center" style="height: 30px; width: 530px">
  <input id="address" type="textbox">
  <input type="button" value="Geocode" onclick="codeAddress()">
  </div>
  <div id="map" style="height:200px; width: 530px"></div>
  </body>
  </html>
  <script>
  var geocoder;
  var map;
  function initialize()
  {
    geocoder = new google.maps.Geocoder();
    map = new google.maps.Map(document.getElementById("map"),
  {
    zoom: 8,
    center: new google.maps.LatLng(22.7964,79.5410),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });
  }

  function codeAddress()
  {
   var address = document.getElementById("address").value;
   geocoder.geocode( { 'address': address}, function(results, status)
   {
    if (status == google.maps.GeocoderStatus.OK)
    {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker(
        {
            map: map,
            position: results[0].geometry.location
        });
    }
    else
    {
        alert("Geocode was not successful for the following reason: " + status);
    }
  });
   }
   </script>

变量位置=[
[Chester',53.183497,-2.890605,3,'https://www.google.co.uk'],
[Manchester',53.474103,-2.243593,2,'https://www.google.co.uk'],
[Liverpool',53.421206,-2.945146,1,'https://www.google.co.uk/']
];
var map=new google.maps.map(document.getElementById('map'){
缩放:9,
中心:新google.maps.LatLng(53.381021,-2.608138),
mapTypeId:google.maps.mapTypeId.TERRAIN,
});
var infowindow=new google.maps.infowindow();
var标记,i;
对于(i=0;i
邮政编码地理编码我有:

  <script type="text/javascript">
  var locations = [
  ['Chester', 53.183497, -2.890605, 3, 'https://www.google.co.uk'],
  ['Manchester', 53.474103, -2.243593, 2, 'https://www.google.co.uk'],
  ['Liverpool', 53.421206, -2.945146, 1, 'https://www.google.co.uk/']
  ];


var map = new google.maps.Map(document.getElementById('map'), {
  zoom: 9,
  center: new google.maps.LatLng(53.381021, -2.608138),
  mapTypeId: google.maps.MapTypeId.TERRAIN,

});

var infowindow = new google.maps.InfoWindow();

var marker, i;

for (i = 0; i < locations.length; i++) {  
  marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    url: locations[i][4],
    map: map
  });

    google.maps.event.addListener(marker, 'dblclick', function() {
            window.location.href = this.url;
        });

  google.maps.event.addListener(marker, 'click', (function(marker, i) {
    return function() {
      infowindow.setContent(locations[i][0]);
      infowindow.open(map, marker);
    }
  })(marker, i));
}
</script>
  <html>
  <head>
  <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  <script type="text/javascript"></script>
  </head>
  <body onload="initialize()">
  <div align="center" style="height: 30px; width: 530px">
  <input id="address" type="textbox">
  <input type="button" value="Geocode" onclick="codeAddress()">
  </div>
  <div id="map" style="height:200px; width: 530px"></div>
  </body>
  </html>
  <script>
  var geocoder;
  var map;
  function initialize()
  {
    geocoder = new google.maps.Geocoder();
    map = new google.maps.Map(document.getElementById("map"),
  {
    zoom: 8,
    center: new google.maps.LatLng(22.7964,79.5410),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });
  }

  function codeAddress()
  {
   var address = document.getElementById("address").value;
   geocoder.geocode( { 'address': address}, function(results, status)
   {
    if (status == google.maps.GeocoderStatus.OK)
    {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker(
        {
            map: map,
            position: results[0].geometry.location
        });
    }
    else
    {
        alert("Geocode was not successful for the following reason: " + status);
    }
  });
   }
   </script>

var地理编码器;
var映射;
函数初始化()
{
geocoder=新的google.maps.geocoder();
map=new google.maps.map(document.getElementById(“map”),
{
缩放:8,
中心:新google.maps.LatLng(22.7964,79.5410),
mapTypeId:google.maps.mapTypeId.ROADMAP
});
}
函数代码地址()
{
var address=document.getElementById(“地址”).value;
geocoder.geocode({'address':address},函数(结果,状态)
{
if(status==google.maps.GeocoderStatus.OK)
{
map.setCenter(结果[0].geometry.location);
var marker=new google.maps.marker(
{
地图:地图,
位置:结果[0]。几何体。位置
});
}
其他的
{
警报(“地理编码因以下原因未成功:“+状态”);
}
});
}

以下示例显示了如何利用
google.maps.Geocoder
显示详细的地址信息,包括邮政编码:

函数initMap(){
var geocoder=new google.maps.geocoder();
变量位置=[
[Chester',53.183497,-2.890605,3,'https://www.google.co.uk'],
[Manchester',53.474103,-2.243593,2,'https://www.google.co.uk'],
[Liverpool',53.421206,-2.945146,1,'https://www.google.co.uk/']
];
var map=new google.maps.map(document.getElementById('map'){
缩放:9,
中心:新google.maps.LatLng(53.381021,-2.608138),
mapTypeId:google.maps.mapTypeId.TERRAIN,
});
var infowindow=new google.maps.infowindow();
对于(变量i=0;i
html,正文{
身高:100%;
保证金:0;
填充:0;
}
#地图{
身高:100%;
}

要通过邮政编码添加标记,需要用邮政编码替换阵列中的纬度/经度坐标,然后对其进行地理编码

// updated array
var locations = [
    ['Manchester', 'M3 3JU', 'https://www.google.co.uk'],
    ['Chester', 'CH1 2DY', 'https://www.google.co.uk'],
    ['Liverpool', 'L3 8EN', 'https://www.google.co.uk/']
];
// geocoding function
function codeAddress(location) {
    geocoder.geocode({
        'address': location[1]
    }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                map: map,
                title: location[1],
                url: locations[2],
                position: results[0].geometry.location
            });
            bounds.extend(marker.getPosition());
            map.fitBounds(bounds);

            google.maps.event.addListener(marker, 'dblclick', function () {
                window.location.href = this.url;
            });

            google.maps.event.addListener(marker, 'click', (function (marker, location) {
                return function () {
                    infowindow.setContent(location[0]);
                    infowindow.open(map, marker);
                };
            })(marker, location));
        } else {
            alert("Geocode was not successful for the following reason: " + status);
        }
    });
}

代码片段:

var位置=[
[‘曼彻斯特’、‘M3 3JU’、'https://www.google.co.uk'],
['Chester','CH1 2DY','https://www.google.co.uk'],
['Liverpool','L3 8EN','https://www.google.co.uk/']
];
var map=new google.maps.map(document.getElementById('map'){
缩放:9,
中心:新google.maps.LatLng(53.381021,-2.608138),
mapTypeId:google.maps.mapTypeId.TERRAIN
});
var infowindow=new google.maps.infowindow();
var geocoder=new google.maps.geocoder();
var bounds=new google.maps.LatLngBounds();
var标记,i;
对于(i=0;i