在Google地图上标记多个位置?

时间:2015-02-02 10:59:05

标签: maps

我从stackoverflow的另一篇文章中复制了这段代码,我对google maps api没有任何经验。

    <html lang="en">

<head>

<meta charset="utf-8">

<meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)">

<meta name="dcterms.created" content="Tue, 08 Jan 2013 05:31:17 GMT">
    <meta name="description" content="">

<meta name="keywords" content="">

<title></title>

<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>

<script>

var geocoder, map;

function initialize() {

geocoder = new google.maps.Geocoder();

var latlng = new google.maps.LatLng(100, 100);

var myOptions = {
    zoom:5,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }

map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

codeAddress();

}


function codeAddress() {

var address = "Bucuresti, Romania";
var address = "Galati, Romania";

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>

</head>

<body onload="initialize()">
 <div id="map_canvas" style="width: 720px; height: 480px;"></div>

</body>
</html>

地图仅显示布加勒斯特标记,如何将其显示为标记的城市。

1 个答案:

答案 0 :(得分:0)

将地址作为参数传递给codeAdress,并将其称为您拥有的多个地址。 目前它只考虑地址[0]