1
1

maps.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. $city = strval($_GET["city"]);
  3. ?>
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <title>百度地图-城市定位</title>
  10. <style type="text/css">
  11. html{height:100%}
  12. body{height:100%;margin:0px;padding:0px}
  13. #container{height:100%}
  14. </style>
  15. <script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=tF8XaCqUG9ZjFR66lqqNXmLzeT24gtGF">
  16. </script>
  17. </head>
  18. <body>
  19. <div id="container"></div>
  20. <script type="text/javascript">
  21. var map = new BMap.Map("container");
  22. // 创建地图实例
  23. var point = new BMap.Point(116.404, 39.915);
  24. // 创建点坐标
  25. map.centerAndZoom(point, 15);
  26. // 初始化地图,设置中心点坐标和地图级别
  27. map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
  28. map.addControl(new BMap.NavigationControl()); // 添加标准地图控件
  29. // 创建地址解析器实例
  30. var myGeo = new BMap.Geocoder();
  31. // 将地址解析结果显示在地图上,并调整地图视野
  32. myGeo.getPoint( "<?php echo $city ?>" , function(point){
  33. if (point) {
  34. map.centerAndZoom(point, 15);
  35. map.addOverlay(new BMap.Marker(point));
  36. map.addControl(new BMap.NavigationControl());
  37. map.addControl(new BMap.ScaleControl());
  38. map.addControl(new BMap.OverviewMapControl());
  39. map.addControl(new BMap.MapTypeControl());
  40. }
  41. },
  42. "<?php echo $city ?>");
  43. </script>
  44. </body>
  45. </html>