BMap学习笔记(一)初始化BMap

   百度地图Api: http://lbsyun.baidu.com/

doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Hello World!title>
<style type="text/css">
html {
    height: 100%
}
body {
    height: 100%;
    margin: 0px;
    padding: 0px
}
#container {
    height: 100%
}
style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=2337624829697af4d7d4884ea113c174">
script>
head>

<body>
<div id="container">div>
<script type="text/javascript"> 
var map = new BMap.Map("container");          // 创建地图实例  
var point = new BMap.Point(116.404, 39.915);  // 创建点坐标  
map.centerAndZoom(point, 10);                 // 初始化地图,设置中心点坐标和地图级别  
script>
body>
html>

    JavaScript API支持异步加载,您可以在引用脚本的时候添加callback参数,当脚本加载完成后callback函数会被立刻调用

DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>异步加载title>
<script type="text/javascript">  
function initialize() {  
  var mp = new BMap.Map('map');  
  mp.centerAndZoom(new BMap.Point(121.491, 31.233), 11);  
}  
   
function loadScript() {  
  var script = document.createElement("script");  
  script.src = "http://api.map.baidu.com/api?v=2.0&ak=2337624829697af4d7d4884ea113c174&callback=initialize"; 
  document.body.appendChild(script);  
}  
   
window.onload = loadScript;  
script>
<style type="text/css">
#map {
    height: 100%
}
body {
    height: 100%;
    margin: 0px;
    padding: 0px
}
html {
    height: 100%
}
style>
head>
<body>
<div id="map">div>
body>
html>

 

转载于:https://www.cnblogs.com/yyxiangjava/p/5667763.html

你可能感兴趣的:(BMap学习笔记(一)初始化BMap)