-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
290 lines (258 loc) · 8.27 KB
/
index.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
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Freemium | Welcome</title>
<link rel="stylesheet" href="css/foundation.css" />
<script src="js/vendor/modernizr.js"></script>
<style>
#map {
width: 500px;
height: 400px;
margin:0 auto;
}
</style>
</head>
<body onload="initialize()">
<nav class="top-bar" data-topbar>
<ul class="title-area">
<li class="name">
<h1><a href="/">Freemium</a></h1>
</li>
</ul>
<section class="top-bar-section">
<!-- Right Nav Section -->
<ul class="right">
<li class="has-form">
<a href="/" class="button success" >Get Blessed</a>
</li>
<li class="has-form">
<a href="share.php" class="button " >Share !!</a>
</li>
</ul>
</section>
</nav>
<br><br>
<div class="row">
<form>
<div class="row">
<div class="large-6 columns">
<label>Search for a address</label>
<input type="text" id="autocomplete" onFocus="geolocate()" placeholder="Its intelligent try it!" />
</div>
<div class="large-6 columns">
<label>Whats you are interested today</label>
<input type="text" id="keywords" placeholder="Search Keywords" />
</div>
</div>
</form>
</div>
<div id="map">
</div>
<hr>
<script>
var geocoder;
var map;
var infoWindow;
var markers = [];
function initialize() {
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
xhr.setRequestHeader("api-key", "3B3CABA50386E2B6502A4A8D95328417");
}
});
initMap();
}
function getCurrentInfo() {
var info = {location: null, keywords: null};
if (place) {
info.location = {lat: place.geometry.location.lat(), lng: place.geometry.location.lng()};
}
if ($("#keywords").val()) {
info.keywords = $("#keywords").val();
}
return info;
}
function searchEvent(info) {
console.log("in search: ");
console.log(info);
console.log(info.location);
console.log(info.keywords);
var reqURL = ("https://free-mium.search.windows.net/indexes/events/docs?api-version=2015-02-28&search=" + (info.keywords ? info.keywords : "*") + ( info.locaiton ? " &$filter=geo.distance(location, geography'POINT(" + info.location.lat + " " + info.location.lng + ")')+le+2" : ""));
console.log(reqURL);
var settings = {
"async": true,
"crossDomain": true,
"url": reqURL,
"method": "GET"
}
$.ajax(settings).done(function (response) {
drawMap( response);
});
}
function drawMap(retData) {
markers.forEach(function (marker) {
marker.setMap(null);
});
markers = [];
if (retData.value.length == 0) return ;
console.log(retData);
if (map) {
/*
var bestEvent = retData.value[0];
var coord = (bestEvent.location.coordinates);
map.setCenter(new google.maps.LatLng(coord[0], coord[1]));
*/
var bounds = new google.maps.LatLngBounds();
// Display multiple markers on a map
for (var i=0; i<retData.value.length; i++) {
var event = retData.value[i];
var gLatLng = new google.maps.LatLng(event.location.coordinates[0], event.location.coordinates[1])
//console.log(event.location.coordinates);
marker = new google.maps.Marker({
map: map,
title: 'title',
animation: google.maps.Animation.DROP,
position: gLatLng
});
markers.push(marker);
bounds.extend(gLatLng);
// Allow each marker to have an info window
google.maps.event.addListener(marker, 'click', (
function(marker, infoWindowContent) {
return function() {
infoWindow.setContent(infoWindowContent);
infoWindow.open(map, marker);
}
})(marker, (
'<div class="info_content">' +
'<h3>' + event.name + '</h3>' +
'<p>' + new Date(event.time_start) + '<p>' +
'<p>' + (event.address_notes ? event.address_notes : '') + ' / ' + event.address + '<p>' +
'<p style="font-size:small;">' + event.description + '</p>' + '</div>')));
}
map.fitBounds(bounds);
}
else {
console.log("map not found");
}
}
/*
function toggleBounce() {
if (marker.getAnimation() !== null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}
*/
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
}
function getCurrentLocation (map) {
var currentPosition = {lat: 0, lng:0};
// Try HTML5 geolocation.
infoWindow = new google.maps.InfoWindow({map: map});
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
currentPosition = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(currentPosition);
infoWindow.setContent('Your Location.');
map.setCenter(currentPosition);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
return currentPosition;
}
function initMap() {
var mapCanvas = document.getElementById('map');
var mapOptions = {
center: new google.maps.LatLng(0,0),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControl: true,
mapTypeControl: true,
scaleControl: true,
streetViewControl: true,
rotateControl: true
};
map = new google.maps.Map(mapCanvas, mapOptions); //global map
var pos = getCurrentLocation(map);
searchEvent({});
}
// This example displays an address form, using the autocomplete feature
// of the Google Places API to help users fill in the information.
var placeSearch, autocomplete;
function initAutocomplete() {
// Create the autocomplete object, restricting the search to geographical
// location types.
autocomplete = new google.maps.places.Autocomplete(
/** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
{types: ['geocode']});
// When the user selects an address from the dropdown, populate the address
// fields in the form.
autocomplete.addListener('place_changed', fillInAddress);
}
var place;
// [START region_fillform]
function fillInAddress() {
// Get the place details from the autocomplete object.
place = autocomplete.getPlace();
//console.log(place);
var info = {location: {lat: place.geometry.location.lat(), lng: place.geometry.location.lng()}};
searchEvent(info);
}
// [END region_fillform]
// [START region_geolocation]
// Bias the autocomplete object to the user's geographical location,
// as supplied by the browser's 'navigator.geolocation' object.
function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var geolocation = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var circle = new google.maps.Circle({
center: geolocation,
radius: position.coords.accuracy
});
autocomplete.setBounds(circle.getBounds());
});
}
}
// [END region_geolocation]
</script>
<script src="js/vendor/jquery.js"></script>
<script src="js/foundation.min.js"></script>
<script src="js/foundation/foundation.topbar.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA1MgYE-d_EX4Jq0b-D-eB2px1NTQxYXW0&signed_in=true&libraries=places&callback=initAutocomplete"
async defer></script>
<script>
$(document).foundation();
$("#keywords").focusout(function(){
console.log('trigger $("#keywords").focusout');
searchEvent({keywords: $("#keywords").val()});
});
$("#keywords").keyup(function(event){
if(event.keyCode == 13){
console.log('trigger $("#keywords").keyup with event.keyCode == 13');
searchEvent({keywords: $("#keywords").val()});
}
});
</script>
</body>
</html>