相信大家都有用过 web 中百度的地图插入功能,有不会的小伙伴可以参考一下:http://api.map.baidu.com/lbsapi/creatmap/
但是对于英文网站来说,不能在页面中使用中文地图吧,那样太掉档了。
1、利用高德地图。百度没有英文版的地图,后来才想到专业做地图的高德地图。去其官网查询相关的 api 调用方法。高德地图没有像百度那样的简单操作界面。需要根据文档去搭配使用。高德地图 api 地址:http://lbs.amap.com/api/javascript-api/example/a/0106-2/
里面有英文版,但又没有定位图标,可以参考开发指南:http://lbs.amap.com/api/javascript-api/guide/draw-on-map/infowindow/ 里面的窗体的介绍。
现在可以把这两个功能整合在一起了,但还有一个问题,就是准确的经纬度定位问题需要解决了。如果不会请问度娘“高德地图坐标拾取器”。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
   | <div id="mapContainer"></div> <div id="btnDiv">     <input id="enMapBtn" type="button" value="显示英文底图" />     <input id="zh_enMapBtn" type="button" value="显示中英文对照底图" />     <input id="zhMapBtn" type="button" value="显示中文底图" /> </div> <script     type="text/javascript"     src="http://webapi.amap.com/maps?v=1.3&key=你申请的key值" ></script> <script type="text/javascript">          var map = new AMap.Map("mapContainer", {         resizeEnable: true,                  view: new AMap.View2D({                          center: new AMap.LngLat(113.908693, 22.556899),                          zoom: 18,         }),     });          map.plugin(["AMap.ToolBar"], function () {         var toolBar = new AMap.ToolBar();         map.addControl(toolBar);     });          addMarker();          function addMarker() {         map.clearMap();         var marker = new AMap.Marker({             map: map,                          position: new AMap.LngLat(113.908693, 22.556899),                          icon: "http://webapi.amap.com/images/0.png",         });                  AMap.event.addListener(marker, "click", function () {             infoWindow.open(map, marker.getPosition());         });     }          var infoWindow = new AMap.InfoWindow({         isCustom: true,                  content: createInfoWindow(             "CMK  ",             "<img src='http://localhost/gtd/Public/home/images/logo.png' style = 'position:relative;float:left;margin:0 5px 5px 0;' > 地址"         ),         offset: new AMap.Pixel(16, -45),      });          function createInfoWindow(title, content) {         var info = document.createElement("div");         info.className = "info";                                    var top = document.createElement("div");         var titleD = document.createElement("div");         var closeX = document.createElement("img");         top.className = "info-top";         titleD.innerHTML = title;         closeX.src = "http://webapi.amap.com/images/close2.gif";         closeX.onclick = closeInfoWindow;         top.appendChild(titleD);         top.appendChild(closeX);         info.appendChild(top);                  var middle = document.createElement("div");         middle.className = "info-middle";         middle.style.backgroundColor = "white";         middle.innerHTML = content;         info.appendChild(middle);                  var bottom = document.createElement("div");         bottom.className = "info-bottom";         bottom.style.position = "relative";         bottom.style.top = "0px";         bottom.style.margin = "0 auto";         var sharp = document.createElement("img");         sharp.src = "http://webapi.amap.com/images/sharp.png";         bottom.appendChild(sharp);         info.appendChild(bottom);         return info;     }          function closeInfoWindow() {         map.clearInfoWindow();     }     map.setLang("en");     
 
 
 
 
 
 
 
 
  </script>
   | 
 
关键代码:
2、高德地图只支持国内地区,利用谷歌地图可以支持查看国外地区。
新建一个 map.php 利用框架的形式 include 中进入,include 时传入相应的值即可。
1 2 3 4 5 6 7 8
   | <?php error_reporting(E_ALL ^ E_NOTICE); $jwd = $_GET['jwd'] ? $_GET['jwd'] : '纬度,经度'; $title = $_GET['title'] ? $_GET['title'] : 'William siteapge'; $jwdA = explode(',', $jwd); $wd = $jwdA[0]; $jd = $jwdA[1]; ?>
   | 
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
   | <!DOCTYPE html> <html>     <head>         <title></title>         <script             type="text/javascript"             src="http://libs.baidu.com/jquery/1.7.0/jquery.min.js"         ></script>         <script             type="text/javascript"             src="http://maps.googleapis.com/maps/api/js?sensor=true&language=en-us&key=AIzaSyDO-TI0nPW2O7VTCRuhHDQ-MocQpckas6U"         ></script>         <script type="text/javascript">             $(function () {                 initialize();             });
              var map = null;                          function initialize() {                 var latlng = new google.maps.LatLng(<?php echo (float)$wd;?>, <?php echo (float)$jd;?>);                  var myOptions = {                     zoom: 15,                     center: latlng,                     mapTypeId: google.maps.MapTypeId.ROADMAP                 };                 map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
 
                  var marker = new google.maps.Marker({                     position: latlng,                     map: map,                     title: "<?php echo $title;?>"                 });
                  var contentString = '<div id="content">' + '<div>' +                     '</div>' +                     '<h2><?php echo $title;?></h2>' +                     '</div>';                 var infowindow = new google.maps.InfoWindow({                     content: contentString                 });                 google.maps.event.addListener(marker, 'click', function () {                     infowindow.open(map, marker);                 });             }         </script>     </head>     <body style="margin:0;padding:0">         <div style="width:820px;height:350px; float: left;">                          <div                 style="width: 820px;; height: 350px; border: 1px solid #C0C0C0;"                 id="map_canvas"             ></div>         </div>     </body> </html>
   | 
 
      
     
    
      
  
  
    
      
      
        
        致力于网站建设与Web开发。喜欢新事物,关注前后端动态,对新的技术有追求, 做一个优秀的web全栈工程师。