-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.html
130 lines (126 loc) · 3.39 KB
/
example.html
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html>
<head>
<title>Place searches</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true&libraries=places"></script>
<script>
var map;
var infowindow;
var pyrmont=new google.maps.LatLng(-30, 30);
var address="12004 Montrose Village Terr rockville MD 20852";
var directionsService = new google.maps.DirectionsService();
var geocode;
var newOne;
function initialize() {
console.log(pyrmont);
geocode = new google.maps.Geocoder();
geo();
}
function geo(){
var request = {
address: address,
};
geocode.geocode(request, callBackGeofunction);
}
function callBackGeofunction(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
pyrmont=results[0].geometry.location;
map = new google.maps.Map(document.getElementById('map-canvas'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: pyrmont,
zoom: 15
});
var request = {
location: pyrmont,
radius: 500,
query: ['soup kitchen','food pantry']
};
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.textSearch(request, callback);
}
}
function kitchen(name, address, location)
{
this.name=name;
this.address=address;
this.location=location;
}
var listOfLocations=new Array;
function callback(results, status) {
console.log(results);
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
listOfLocations.push(new kitchen(results[i].name, results[i].formatted_address, results[i].geometry.location));
}
console.log(print(listOfLocations));
}
}
function print(array){
var ret="";
for(var i=0;i<array.length;i++){
ret=ret+(array[i].name + " " + array[i].address + "\n");
}
return ret;
}
function printDir(name){
var loc;
var ret="";
for (var i = 0; i < listOfLocations.length; i++) {
if(listOfLocations[i].name==name){
loc=listOfLocations[i].location;
break;
}
}
var request={
origin:pyrmont,
destination: loc.toString(),
travelMode: google.maps.TravelMode.WALKING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
console.log(response);
console.log(response.routes[0].legs[0].steps);
for (var i = 0; i < response.routes[0].legs[0].steps.length; i++) {
ret+=response.routes[0].legs[0].steps[i].instructions+"\n";
}
console.log(ret);
}
});
return loc;
}
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas" style="width: 50%; float:left"></div>
<div style="width:46%; float:left">
<pre>
var request = {
location: new google.maps.LatLng(-33.8665433, 151.1956316),
radius: 500,
types: ['soup kitchen']
};
</pre>
</body>
</html>