- <html>
- <head>
- </head>
- <script type="text/javascript" src1="http://maps.google.com/maps/api/js?sensor=true"></script>
- <script type="text/javascript">
- <!--
- var geocoder;
- var map;
- function initialize() {
- geocoder = new google.maps.Geocoder();
- //初始中心位置(纬、经度)
- var latlng = new google.maps.LatLng(32.58384932565665,104.864501953125);
- var myOptions = {
- zoom: 4,
- center: latlng,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- }
- map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
- setTimeout("codeAddress()",3000);
- }
- function codeAddress() {
- var allAddress = "36.56260003738553,106.995849609375;34.27083595165003,94.932861328125;35.755428369259704,109.127197265625;33.68778175843944,112.071533203125;28.777289039997672,113.97216796875;26.509904531414005,116.751708984375;23.77529123645146,113.9501953125;22.32975230437656,110.8740234375;29.659416054912448,110.654296875"
- if (geocoder) {
- var addArr = allAddress.split(";");
- for(var i=0;i<addArr.length;i++){
- geocoder.geocode( { 'address': addArr[i]}, 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
- });
- var con = '姓名: test <br> 时间: 2012-06-05 <br>所在地:' + results[0].formatted_address;
- attachSecretMessage(marker, con);
- } else {
- alert("Geocode was not successful for the following reason: " + status);
- }
- });
- }
- }
- }
- function attachSecretMessage(marker, mycontent) {
- var infowindow = new google.maps.InfoWindow({
- content : mycontent,
- size : new google.maps.Size(50, 50)
- });
- google.maps.event.addListener(marker, 'mouseover', function(response) {
- infowindow.open(map, marker);
- });
- google.maps.event.addListener(marker, 'mouseout', function(response) {
- infowindow.close();
- });
- }
- //-->
- </script>
- <body onload="initialize()">
- <div id="map_canvas" style="width: 100%; height: 480px;"></div>
- </body>
- </html>
- //该片段来自于http://www.codesnippet.cn/detail/200620134183.html
来源: http://www.codesnippet.cn/detail/200620134183.html