首页 > 其他 > 详细

百度地图-设置默认城市

时间:2016-05-13 02:48:37      阅读:278      评论:0      收藏:0      [点我收藏+]

1、问题背景

     利用百度地图,展示某城市地图分布;初始化时,默认打开就是该城市


2、实现源码

<!DOCTYPE html>
<html>
  <head>
    <title>设置默认城市地图</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=ak密钥"></script>
	<style>
		body,html,#map{
			width: 100%;
			height: 100%;
			overflow: hidden;
			margin: 0;
			font-size: 12px;
			font-family: "微软雅黑";
		}
	</style>

  </head>
  
  <body>
     <div id="map"></div>
  </body>
</html>
<script>
   var map = new BMap.Map("map");
   //初始化地图,centerAndZoom第一个参数为Point时,第二个参数的范围是3-19;对于移动端,centerAndZoom第一个参数为Point时,第二个参数的范围是3-18
   map.centerAndZoom(new BMap.Point(114.309531, 30.59619),50);
   //将控件添加到地图,一个控件实例只能向地图中添加一次
   map.addControl(new BMap.MapTypeControl());
   //设置地图显示的城市,默认为武汉
   map.setCurrentCity("武汉");
   //开启鼠标滚轮缩放
   map.enableScrollWheelZoom(true);
   //禁用地图拖拽
   map.disableDragging(true);
</script>

3、实现结果

技术分享

百度地图-设置默认城市

原文:http://blog.csdn.net/you23hai45/article/details/51340553

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!