百度地图api实例

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm11.aspx.cs" Inherits="JQGridExercise.WebForm11" %>

<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:"微软雅黑";font-size:14px;}
#allmap {width:100%;height:500px;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=63i90lOgvKon1KU0AnLGgGkC"></script>
<title>逆地址解析</title>
</head>
<body>
<div id="allmap" style="width:1200px;height:600px;"></div>
<p>点击地图展示详细地址</p>
</body>
</html>
<script type="text/javascript">
// 百度地图API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398, 39.897445);
map.centerAndZoom(point, 12);
map.enableScrollWheelZoom(true);
var geoc = new BMap.Geocoder();
map.addControl(new BMap.NavigationControl({ anchor: BMAP_ANCHOR_TOP_RIGHT, offset: new BMap.Size(40, 60) })); // 添加平移缩放控件
var pointArray = new Array();
map.addEventListener("click", function (e) {
var pt = e.point;
var pointArray = new Array();
var marker = new BMap.Marker(new BMap.Point(e.point.lng, e.point.lat)); // 创建点
map.addOverlay(marker); //增加点
pointArray[0] = new BMap.Point(e.point.lng, e.point.lat);
//marker.addEventListener("click", attribute);


geoc.getLocation(pt, function (rs) {

var addComp = rs.addressComponents;
//alert(e.point.lng + ", " + e.point.lat);
alert(rs.address);
});
});
</script>

你可能感兴趣的:(百度地图)