<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:"微软雅黑";}
#l-map{height:300px;width:100%;}
#r-result,#r-result table{width:100%;}
</style>
<title>驾车导航的结果面板</title>
</head>
<body>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2"></script>
<div id="l-map"></div>
<div id="r-result"></div>
</body>
</html>
<script type="text/javascript">
// 百度地图API功能
var map = new BMap.Map("l-map");
map.centerAndZoom(new BMap.Point(116.404, 39.915), 12);
var driving = new BMap.DrivingRoute(map, {renderOptions: {map: map, panel: "r-result", autoViewport: true}});
driving.search("中关村一街", "魏公村");
</script>
<script type="text/javascript">
/*************js实现*************/
$(document).ready(function(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(getPositionSuccess, getPositionError);
}else{
alert("您的浏览器不支持自动定位!");
}
});
/***用户定位成功**/
function getPositionSuccess(position){
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var address;
//通过baiduMap API获取街道名称
var map = new BMap.Map("allmap");
var point = new BMap.Point(lng,lat);
var gc = new BMap.Geocoder();
gc.getLocation(point, function(rs){
var addComp = rs.addressComponents;
address = addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber;
alert("address="+address);
});
alert("longitude="+lng+" latitude="+lat);
}
/**用户定位失败**/
function getPositionError(error){
switch(error.code){
case error.TIMEOUT:
alert("连接超时,请重试");
break;
case error.PERMISSION_DENIED:
alert("您拒绝了使用位置共享服务,查询已取消");
break;
case error.POSITION_UNAVAILABLE:
alert("亲爱的火星网友,非常抱歉,我们暂时无法为您所在的星球提供位置服务");
break;
}
}
</script>
请问这两段代码如何融合起来改为自动获取当前位置呢