My Google search skills a开发者_JS百科re failing me today. I can add one pin to a Google map using a UK post code. But I can't find how to add multiple pins from a selection of say 100 post codes.
All help apprecaited!
You may want to check out the following example. I believe it should be self explanatory for you to follow:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps API Geocoding Demo</title>
<script src="http://maps.google.com/maps?file=api&v=2&sensor=false"
type="text/javascript"></script>
</head>
<body onunload="GUnload()">
<div id="map_canvas" style="width: 400px; height: 300px"></div>
<script type="text/javascript">
var geocoder = new GClientGeocoder();
var map = new GMap2(document.getElementById("map_canvas"));
var i;
var postcodes = [
'SL59JH',
'LU13TQ',
'SR29TD',
'DA75BQ',
'EC1V9B'
];
map.setCenter(new GLatLng(54.00, -3.00), 5);
for (i = 0; i < postcodes.length; i++) {
geocoder.getLatLng(postcodes[i] + ', UK', function (point) {
if (point) {
map.addOverlay(new GMarker(point));
}
});
}
</script>
</body>
</html>
Screenshot:
精彩评论