标签:
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=5dacabfc3bd5924cdb6373195dcf68a0"></script>
<script type="text/javascript">
var map, geolocation;
var lng, lat;
//加载地图,调用浏览器定位服务
map = new AMap.Map(‘iCenter‘, {
resizeEnable: true
});
map.plugin(‘AMap.Geolocation‘, function () {
geolocation = new AMap.Geolocation({
enableHighAccuracy: true,//是否使用高精度定位,默认:true
timeout: 10000, //超过10秒后停止定位,默认:无穷大
buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
zoomToAccuracy: true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
buttonPosition: ‘RB‘
});
map.addControl(geolocation);
geolocation.getCurrentPosition();
AMap.event.addListener(geolocation, ‘complete‘, onComplete);//返回定位信息
AMap.event.addListener(geolocation, ‘error‘, onError); //返回定位出错信息
});
//解析定位结果
function onComplete(data) {
var str = [‘定位成功‘];
str.push(‘经度:‘ + data.position.getLng());
str.push(‘纬度:‘ + data.position.getLat());
alert(str);
lng = data.position.getLng();
lat = data.position.getLat();
}
//解析定位错误信息
function onError(data) {
alert(‘定位失败‘);
}
function Guide() {
window.location.href = "http://m.amap.com/navi/?start=" + lng + "," + lat + "&dest=<%=config.coordinateX%>,<%=config.coordinateY%>&destName=西路桥大道880-8号&naviBy=car&key=5dacabfc3bd5924cdb6373195dcf68a0";
}
</script>
标签:
原文地址:http://www.cnblogs.com/liandy0906/p/5824896.html