点击这个按钮,获得您的位置:
<script><BR>var x=document.getElementById("demo");<BR>function getLocation(){<BR> if(navigator.geolocation){<BR> navigator.geolocation.getCurrentPosition(showPosition);<BR> }else{<BR> alert("您的浏览器不支持地理定位");<BR> }<BR> }
<P>function showPosition(position){<BR> lat=position.coords.latitude;<BR> lon=position.coords.longitude;<BR> //var map = new BMap.Map("container"); // 创建Map实例<BR> var point = new BMap.Point(lon, lat); // 创建点坐标<BR> //map.centerAndZoom(point,15); // <BR> //map.enableScrollWheelZoom(); <BR> var gc = new BMap.Geocoder(); <BR> gc.getLocation(point, function(rs){<BR> var addComp = rs.addressComponents;<BR> alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street);<BR> });<BR> }<BR></script>