-
Notifications
You must be signed in to change notification settings - Fork 0
/
gps.js
76 lines (70 loc) · 2.29 KB
/
gps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*--------------------------------------point-------------------------------------------*/
var _stationStart = ''
var _stationEnd = ''
var t
function getgps(Start, End) {
// var base = "http://api.map.baidu.com/direction"
// var base = "http://api.map.baidu.com/direction/v2"
let stationStart = $("#start").val()
let stationEnd = $("#end").val()
console.log(stationStart + "======" + stationEnd)
if(stationStart) {
getPonit(stationStart, true)
}
if(stationEnd) {
getPonit(stationEnd, false)
}
t = setTimeout("gpsList()", 3000)
}
//getgpslist
function gpsList() {
console.log(_stationEnd + "---------" + _stationEnd)
var url = "http://api.map.baidu.com/direction/v2/transit?origin=" + _stationStart + "&destination=" + _stationEnd + "&tactics_incity=5&ak=jaVfZoevhZsUkKUvaKFsRxHi1HpHyPqG" +
"&callback=gps";
$.getScript(url);
}
function gps(data) {
console.log(data)
var _data = data.result.routes
var line = ''
for(var i = 0, len = _data.length; i < len; i++) {
for(var j = 0, length = _data[i].steps.length; j < length; j++) {
if(_data[i].steps[j][i].vehicle_info.type == 3) {
line = $('<div class="odd"><div>' + _data[i].steps[j][i].instructions + '</div><div>' + _data[i].steps[j][i].path + '</div></div>')
$('#path').append(line)
}
}
}
if(data.message === '成功') {
clearTimeout(t)
}
}
//地理坐标获取
function getPonit(obj, isStation) {
if(isStation) {
var url = "http://api.map.baidu.com/geocoder/v2/?address=" + obj + "&city=北京市&output=json&ak=jaVfZoevhZsUkKUvaKFsRxHi1HpHyPqG" +
"&callback=pointStart";
$.getScript(url);
} else if(!isStation) {
var url = "http://api.map.baidu.com/geocoder/v2/?address=" + obj + "&city=北京市&output=json&ak=jaVfZoevhZsUkKUvaKFsRxHi1HpHyPqG" +
"&callback=pointEnd";
$.getScript(url);
}
}
function pointStart(data) {
var lat = data['result']['location']['lat']
var lng = data['result']['location']['lng']
_stationStart = lat + "," + lng
}
function pointEnd(data) {
var lat = data.result.location.lat
var lng = data.result.location.lng
_stationEnd = lat + "," + lng
}
/*--------------------------------------point-------------------------------------------*/
function changeValue() {
let stationStart = $("#start").val()
let stationEnd = $("#end").val()
$("#end").val(stationStart)
$("#start").val(stationEnd)
}