-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplacessearch2.html
More file actions
254 lines (218 loc) · 7.74 KB
/
placessearch2.html
File metadata and controls
254 lines (218 loc) · 7.74 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="HandheldFriendly" content="true">
<link rel="stylesheet" type="text/css" href="style.css" media="screen, handheld" />
<link rel="stylesheet" type="text/css" href="enhanced.css" media="screen and (min-width: 40.5em)" />
<!--[if (lt IE 9)&(!IEMobile)]>
<link rel="stylesheet" type="text/css" href="enhanced.css" />
<![endif]-->
<script type="text/javascript" src="js/modernizr.js"></script>
<style>
html, body, #map-canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
}
.cbutton{
width:330px;
height:60px;
}
.divbutton{
width:300px;
text-align:center;
margin:0px auto;
}
.controls {
margin-top: 16px;
border: 1px solid transparent;
border-radius: 2px 0 0 2px;
box-sizing: border-box;
-moz-box-sizing: border-box;
height: 32px;
outline: none;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
#pac-input {
background-color: #fff;
padding: 0 11px 0 13px;
width: 400px;
font-family: Roboto;
font-size: 15px;
font-weight: 300;
text-overflow: ellipsis;
}
#pac-input:focus {
border-color: #4d90fe;
margin-left: -1px;
padding-left: 14px;
width: 401px;
}
.pac-container {
font-family: Roboto;
}
#type-selector {
color: #fff;
background-color: #4d90fe;
padding: 5px 11px 0px 11px;
}
#type-selector label {
font-family: Roboto;
font-size: 13px;
font-weight: 300;
}
</style>
<title>Places search box</title>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="js/geoPosition.js" type="text/javascript"></script>
<script src="js/geoPositionSimulator.js" type="text/javascript"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
<script>
var infowindow;
var map;
var geocoder;
function initialize() {
geocoder = new google.maps.Geocoder();
var markers = [];
map = new google.maps.Map(document.getElementById('map-canvas'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoom: 15
});
infowindow = new google.maps.InfoWindow();
var defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(-33.8902, 151.1759),
new google.maps.LatLng(-33.8474, 151.2631));
map.fitBounds(defaultBounds);
// Create the search box and link it to the UI element.
var input = /** @type {HTMLInputElement} */(
document.getElementById('pac-input'));
map.controls[google.maps.ControlPosition.TOP_CENTER].push(input);
var searchBox = new google.maps.places.SearchBox(
/** @type {HTMLInputElement} */(input));
google.maps.event.addListener(searchBox, 'places_changed', function() {
var places = searchBox.getPlaces();
if (places.length == 0) {
return;
}
for (var i = 0, marker; marker = markers[i]; i++) {
marker.setMap(null);
}
// For each place, get the icon, place name, and location.
markers = [];
var bounds = new google.maps.LatLngBounds();
for (var i = 0, place; place = places[i]; i++) {
var image = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};
// Create a marker for each place.
var marker = new google.maps.Marker({
map: map,
icon: image,
title: place.name,
position: place.geometry.location
});
markers.push(marker);
attachInstructionText(marker, place);
bounds.extend(place.geometry.location);
var str = place.name + place.formatted_address + " Lat:" + marker.position.lat() + ",Long:" + marker.position.lng();
document.getElementById('current').innerHTML = str;
}
map.fitBounds(bounds);
});
// [END region_getplaces]
google.maps.event.addListener(map, 'bounds_changed', function() {
var bounds = map.getBounds();
searchBox.setBounds(bounds);
});
}
function attachInstructionText(marker, place) {
google.maps.event.addListener(marker, 'click', function () {
var str = place.name + place.formatted_address + " Lat:" + marker.position.lat() + ",Long:" + marker.position.lng();
//document.getElementById('current').innerHTML = str;
infowindow.setContent(str);
infowindow.open(map, marker);
});
}
function trackLocation() {
var locations = new Array({
coords: {
latitude: 0,
longitude: 0
}
});
geoPositionSimulator.init(locations);
if (geoPosition.init()) {
document.getElementById('current').innerHTML = "Receiving...";
geoPosition.getCurrentPosition(showPosition, function () {
document.getElementById('current').innerHTML = "Couldn't get location"
}, { enableHighAccuracy: true });
}
else {
document.getElementById('current').innerHTML = "Functionality not available";
}
}
function showPosition(p) {
var latitude = parseFloat(p.coords.latitude);
var longitude = parseFloat(p.coords.longitude);
//document.getElementById('current').innerHTML = "latitude=" + latitude + " longitude=" + longitude;
var pos = new google.maps.LatLng(latitude, longitude);
geocoder.geocode({ 'latLng': pos }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
map.setCenter(pos);
map.setZoom(18);
marker = new google.maps.Marker({
position: pos,
map: map
});
var str = results[1].formatted_address + " ,Lat:" + pos.lat() + " ,Long:" + pos.lng();
document.getElementById('current').innerHTML = str;
infowindow.setContent(str);
infowindow.open(map, marker);
} else {
alert('No results found');
}
} else {
alert('Geocoder failed due to: ' + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<style>
#target {
width: 345px;
}
</style>
</head>
<body>
<div class="divbutton">
<input type="button" value="Track My Current Location" class="btn cbutton" onclick="return trackLocation()" />
<br />
<div id="current"></div>
</div>
<input id="pac-input" class="controls" type="text" placeholder="Search Box">
<div id="map-canvas"></div>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/init.js "></script>
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-55890542-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>