-
Notifications
You must be signed in to change notification settings - Fork 3
/
amap.js
115 lines (105 loc) · 4.38 KB
/
amap.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var amap_key = "341c6d9e9840212d799314a326a44857"
var car_id = "abcd123456"
var width = 200
var height = 200
var zoom = 10
var latitude = 22.5574462
var longitude = 113.9449748
function sendXMLHttpRequest(url, callback){
var req = new XMLHttpRequest;
req.open("GET",url);
req.onreadystatechange = function() {
var status = req.readyState;
if (status === XMLHttpRequest.DONE) {
// var objectArray = JSON.parse(req.responseText);
// console.debug(req.responseText)
callback(JSON.parse(req.responseText));
}
}
req.send();
}
//http://restapi.amap.com/v3/staticmap?location=116.481485,39.990464&zoom=10&size=750*300&traffic=1&key=341c6d9e9840212d799314a326a44857
//http://restapi.amap.com/v3/staticmap?location=22.5750427,113.92297&zoom=7&size=180*120&traffic=1&key=341c6d9e9840212d799314a326a44857
//静态地图
function getAMapSource() {
var url = "http://restapi.amap.com/v3/staticmap?location="
url = longitude "," latitude
url = "&zoom=" zoom
url = "&size=" width "*" height
url = "&traffic=1"
url = "&key=" amap_key
return url
}
// AMAP_API.getGeoCode("流塘路口","深圳", function(geo){
// for(var i in geo.geocodes){
// console.debug()
// var location = geo.geocodes[i].location.split(",")
// testItem.center.latitude = location[1]
// testItem.center.longitude = location[0]
// map.center = testItem.center
// }
// })
function getGeoCode(address, city, callback){
var url = "http://restapi.amap.com/v3/geocode/geo?key=" amap_key
url = "&address=" address "&city=" city
sendXMLHttpRequest(url,callback)
}
//抓路服务
// AMAP_API.locations_info.push({location:"116.496167,39.917066",time:"1434077500",direction:"1",speed:"1"})
// AMAP_API.locations_info.push({location:"116.496149,39.917205",time:"1434077501",direction:"1",speed:"1"})
// AMAP_API.locations_info.push({location:"116.496149,39.917326",time:"1434077510",direction:"2",speed:"2"})
// AMAP_API.getAutoGrasp(function(grasp){
// console.debug("grasp",grasp.info)
// for(var i in grasp.roads){
// console.debug("G:",grasp.roads[i].roadname, grasp.roads[i].crosspoint)
// }
// })
var locations_info = new Array
//AMAP_API.locations_info.push({location:"116.496167,39.917066",time:"1434077500",direction:"1",speed:"1"})
function getAutoGrasp(infos,callback){
var locations="", time="", direction="", speed=""
for(var i in infos)
{
locations = infos[i].location "|"
time = infos[i].time ","
direction = infos[i].direction ","
speed = infos[i].speed ","
}
locations = locations.substring(0, locations.lastIndexOf('|'));
time = time.substring(0, time.lastIndexOf(','));
direction = direction.substring(0, direction.lastIndexOf(','));
speed = speed.substring(0, speed.lastIndexOf(','));
var url = "http://restapi.amap.com/v3/autograsp?key=" amap_key
url = "&carid=" car_id
url = "&locations=" locations
url = "&time=" time
url = "&direction=" direction
url = "&speed=" speed
console.debug(url)
sendXMLHttpRequest(url,callback)
locations.length = 0
}
//路径规划--驾车路径规划
// var origin="116.481028,39.989643",destination="116.434446,39.90816"
// AMAP_API.getDrivingDirection(origin, destination, function(driving){
// console.debug("driving.info",driving.info)
// })
function getDrivingDirection(origin, destination,callback){
var url = "http://restapi.amap.com/v3/direction/driving?key=" amap_key
url = "&origin=" origin
url = " &destination=" destination
sendXMLHttpRequest(url,callback)
}
//输入提示
function getInputtips(keywords, callback){
var url = "http://restapi.amap.com/v3/assistant/inputtips?key=" amap_key
url = "&keywords=" keywords
url = "&location=" longitude "," latitude
url = "&datatype=all"
sendXMLHttpRequest(url,callback)
}
function getWeatherInfo(city, callback){
var url = "http://restapi.amap.com/v3/weather/weatherInfo?key=" amap_key
url = "&city=" city
sendXMLHttpRequest(url, callback)
}