Created
March 30, 2016 13:52
-
-
Save hihell/a1ad49fc6e5d089d3270f1f078fde975 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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, #allmap { | |
width: 100%; | |
height: 100%; | |
overflow: hidden; | |
margin: 0; | |
font-family: "微软雅黑"; | |
} | |
</style> | |
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=o0RuzQRVNo1YuIorz50uWVLs6DXVSo7X"></script> | |
<title>步行导航检索</title> | |
</head> | |
<body> | |
<div id="allmap"></div> | |
</body> | |
</html> | |
<script type="text/javascript"> | |
var walkingDistance = null | |
var drivingDistance = null | |
var getDistance = function(start, end) { | |
var map = new BMap.Map("allmap"); | |
var printResult = function(walkingResult) { | |
if (walkingDistance !== null) {return} | |
console.log('printResult') | |
var walkingPlan = walkingResult.getPlan(0) | |
walkingDistance = walkingPlan.getDistance(true) | |
alert('走路距离:' + walkingDistance + '\n' + '开车距离:' + drivingDistance) | |
} | |
var searchWalking = function (drivingResult) { | |
if(drivingDistance !== null) { return } | |
console.log('searchWalking') | |
var drivingPlan = drivingResult.getPlan(0) | |
drivingDistance = drivingPlan.getDistance(true) | |
var walking = new BMap.WalkingRoute(map, {renderOptions: {map: map, autoViewport: true}, onSearchComplete: printResult}) | |
walking.search(start, end) | |
} | |
var driving = new BMap.DrivingRoute(map, {renderOptions: {map: map, autoViewport: true}, onSearchComplete: searchWalking}) | |
driving.search(start, end) | |
} | |
// // 百度地图API功能 | |
getDistance('纽约客公寓', '西屋国际') | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment