标签:options meta font family var arch out UNC 初始化
先进入百度地图API申请密钥
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
#allmap{width:100%;height:500px;}
p{margin-left:5px; font-size:14px;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=输入密钥"></script>
<title>根据关键字本地搜索</title>
</head>
<body>
<div id="allmap"></div>
<p>返回成都市“高校”关键字的检索结果,并展示在地图上</p>
</body>
</html>
<script type="text/javascript">
// 百度地图API功能
var map = new BMap.Map("allmap"); // 创建Map实例
map.centerAndZoom("成都",0); // 初始化地图,用城市名设置地图中心点
var local = new BMap.LocalSearch(map, {
renderOptions:{map: map}
});
local.search("高校");
setTimeout(function(){
map.setZoom(14);
}, 2000); //2秒后放大到14级
map.enableScrollWheelZoom(true);
//单击获取点击的经纬度
map.addEventListener("click",function(e){
alert(e.point.lng + "," + e.point.lat);
});
</script>
标签:options meta font family var arch out UNC 初始化
原文地址:https://www.cnblogs.com/dal3546/p/10201941.html