<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>测试定位</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script>
<style type="text/css">
#mapContainer{100%;height:400px;border:1px solid gray;}</style>
</head>
<body>
<div id="mapContainer"></div>
<script type="text/javascript" >
var origin = "0,0";
var origin_region = "";
var point = new BMap.Point(118.185789, 24.489321);
var map = new BMap.Map("mapContainer");
map.enableScrollWheelZoom();
map.centerAndZoom(point, 15);
var marker = new BMap.Marker(point);
map.addOverlay(marker);
var gectrl=new BMap.GeolocationControl( {
anchor:BMAP_ANCHOR_TOP_LEFT,
enableAutoLocation: true });
map.addControl(gectrl); //添加定位控件
var myCity = new BMap.LocalCity();
myCity.get(function(result){ origin_region = result.name; });
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function (r) {
if (this.getStatus() == BMAP_STATUS_SUCCESS ) {
origin = r.point.lng + "," + r.point.lat;
alert(origin);
}
})
</script>
</body></html>