-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_shop.php
407 lines (367 loc) · 14.8 KB
/
add_shop.php
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<?php require_once("includes/Marker.php");?>
<?php require_once("includes/global.php");?>
<!DOCTYPE HTML>
<html>
<head>
<!--Map set to 100%, not resizable by user-->
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
/*#map_canvas { height: 100% }*/
.info { width: 250px; }
</style>
<!--Sensor means using GPS locator to determine the user's location-->
<script type="text/javascript" src="../common/scripts/jquery/jquery.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true">//sensor=set_to_true_or_false</script>
<script type="text/javascript" src="http://code.google.com/apis/gears/gears_init.js"></script>
<script type="text/javascript"
src="http://www.google.com/jsapi?key=ABQIAAAA-O3c-Om9OcvXMOJXreXHAxQGj0PqsCtxKvarsoS-iqLdqZSKfxS27kJqGZajBjvuzOBLizi931BUow">
</script>
<script type="text/javascript">
var geocoder;
var initialLocation;
var browserSupportFlag = new Boolean();
var map;
var myMarker;
function initialize()
{
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
//var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var myOptions = {
zoom: 14,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map($("#map_canvas").get(0), myOptions);
// test KML
// geoXml = new google.maps.KmlLayer('http://api.flickr.com/services/feeds/geo/?g=322338@N20&lang=en-us&format=feed-georss');
// geoXml.setMap(map);
//var market_latLng = new google.maps.LatLng(map.center.Ra, map.center.Qa);
//console.log(market_latLng);
myMarker = new google.maps.Marker({
//position: location,
position: latlng,
map: map,
draggable: true,
icon: 'markers/youAreHere.png',
title:'you are here!'
});
//map.addOverlay(marker);
// On marker Drag
google.maps.event.addListener(myMarker, "dragend", function(event) {
$('#x_coord').val(event.latLng.Ra);
$('#y_coord').val(event.latLng.Qa);
});
// On map click
google.maps.event.addListener(map, "click", function(event) {
myMarker.setPosition(event.latLng);
$('#x_coord').val(event.latLng.Ra);
$('#y_coord').val(event.latLng.Qa);
});
/*
When map is being dragged
google.maps.event.addListener(map, "drag", function(event) {
marker.setPosition(event.latLng);
console.log(map.getBounds());
{Z.b, Z.d, aa.b, aa.d}
$('#x_coord').val(event.latLng.Pa);
$('#y_coord').val(event.latLng.Qa);
});
google.maps.event.addListener(map, "click", function(event) {
alert("You clicked the map.");
placeMarker(event.latLng);
});
*/
}
function getCenterLatLngText() {
return '(' + map.getCenter().lat() +', '+ map.getCenter().lng() +')';
}
//1.Make only 1 marker
//2.Make it draggable
//3.Populate coords from marker
function placeMarker(location)
{
//console.log(marker);
marker.position = location;
marker.map = map;
$('#x_coord').val(location.Ra);
$('#y_coord').val(location.Qa);
//map.setCenter(location);
}
// Try W3C Geolocation (Preferred)
if(navigator.geolocation) {
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(
function(position) {
initialLocation =
new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
map.setCenter(initialLocation);
}, function() {
handleNoGeolocation(browserSupportFlag);
});
}
// Try Google Gears Geolocation
else if (google.gears) {
browserSupportFlag = true;
var geo = google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition(
function(position) {
initialLocation =
new google.maps.LatLng(position.latitude,
position.longitude);
map.setCenter(initialLocation);
}, function() {
handleNoGeoLocation(browserSupportFlag);
});
}
// Browser doesn't support Geolocation
else {
browserSupportFlag = false;
handleNoGeolocation(browserSupportFlag);
}
function geoCodeAddress()
{
var address = $("address").val();
geocoder.geocode( {'address': address}, function (results, status)
{
if (status = google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
// Map Marker
var marker2 = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
icon: 'markers/youAreHere.png'
});
}
else {
alert("Geocode was not successful:" + status);
}
});
}
function searchLocations()
{
var address = $('#addressInput').val();
geocoder.geocode({'address': address}, function(results,status) {
if (status = google.maps.GeocoderStatus.OK) {
var location = results[0].geometry.location;
map.setCenter(location);
myMarker.setPosition(location);
$('#x_coord').val(location.Ra);
$('#y_coord').val(location.Qa);
searchLocationsNear(results);
}
else {
alert("Geocode was not successful:" + status);
}
});
}
function searchLocationsNear(results)
{
//console.log("Qa/Lat:" + results[0].geometry.location.lat());
//console.log("Ra/Lng:" + results[0].geometry.location.lng());
var radius = $('#radiusSelect').val();
var limit = $('#limit').val();
var searchUrl = 'js/markersAjax.php?type=json&lat='+results[0].geometry.location.Qa+'&lng='+results[0].geometry.location.Ra+'&radius='+radius+'&limit='+limit;
$('#sidebar').html('');
$.getJSON(searchUrl, function(data)
{
$.each(data, function(key,value)
{
// Creating a Lat and Lng coordinates
var latlng = new google.maps.LatLng(
parseFloat(value['lat']),
parseFloat(value['lng'])
);
// Creating a Market with coordinates from Lat and Lng
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: value['name']
});
// Creating an InfoWindow with the content text: "Hello World"
var infoWindow = new google.maps.InfoWindow({
content: '<div><b>'+value['name']+'</b><br />'+value['address']+'<br /></div>'
});
// Adding a click event to the marker
google.maps.event.addListener(marker, 'click', function() {
// Calling the open method of the infoWindow
infoWindow.open(map, marker);
});
createSidebarEntry(marker, value['name'], value['address'], parseFloat(value['distance']));
});
});
}
function createSidebarEntry(marker, name, address, distance)
{
//distance.toFixed(2)
var text = '<div><b>' + name + '</b><br />';
text+= '<i>' + address + '</i><br />';
text+= '<pre>' + distance.toFixed() + ' miles</pre></div>';
$(text).appendTo($('#sidebar'));
//$('#sidebar').style.cursor = 'pointer';
//$('#sidebar').style.marginBottom = '5px';
google.maps.event.addDomListener($('#sidebar'), 'click', function() {
google.maps.event.trigger(marker, 'click');
});
return false;
}
</script>
</head>
<body onload="initialize();">
<form action="SERVER::PHP_SELF" style="height:30%">
<table>
<tr>
<td style="width:50%;">
<table style="height:100%;">
<tr>
<th>
Shop Name
</th>
<td>
<input type="text" value="" name="shop_name"/>
</td>
<!--
<td>
Phone
<input type="text" value="" name="phone"/>
</td>
-->
</tr>
<tr>
<th>
Address
</th>
<td>
<input type="text" value="" name="address"/>
</td>
<!--
<td>
Address_2
<input type="text" value="" name="address_2"/>
</td>
<td>
Address_3
<input type="text" value="" name="address_3"/>
</td>
<td>
Zip
<input type="text" value="" name="zip"/>
</td>
-->
</tr>
<tr>
<th>
Shop Category:
</th>
<td>
<select name="shop_category">
<option></option>
</select>
</td>
</tr>
<tr>
<th>
Latitude (X/Ra)
</th>
<td>
<input type="text" value="" name="x_coord" id="x_coord">
</td>
</tr>
<tr>
<th>
Longitude (Y/Qa)
</th>
<td>
<input type="text" value="" name="y_coord" id="y_coord">
</td>
</tr>
<tr>
<th>
<input type="submit" value="Add"/>
</th>
</tr>
</table>
</td>
<td style="width:50%;">
<table style="height:100%;">
<tr>
<th>
Markers (Shops) available:
</th>
<td>
<select>
<?php
foreach (Marker::getMarkers() as $r) {
?><option value="<?=$r->id;?>"><?=$r->name.' ['.substr($r->address,strlen($r->address)-2,strlen($r->address)).']';?></option><?php
}
?>
</select>
<!--Test-->
<!--<select>-->
<?php
$r = Marker::getMarkers(array('closest'=>500,'closest_lat'=>-74.372462,'closest_lng'=>40.649923));
//print_var($r);
?>
<!--</select>-->
</td>
</tr>
<tr>
<th>
Address:
</th>
<td>
<input type="text" id="addressInput" value="Brighton Beach Ave"/></td>
</td>
</tr>
<tr>
<th>
Radius:
</th>
<td>
<select id="radiusSelect">
<option value="25" selected>25</option>
<option value="100">100</option>
<option value="200">200</option>
<option value="3200">3200</option>
<option value="10000">10000</option>
</select>
<b>Limit:</b>
<input type="text" id="limit" value="20" style="width:35px;"/>
</td>
</tr>
<tr>
<th></th>
<td><input type="button" onclick="searchLocations()" value="Search Locations"/></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<table style="width:100%;height:70%;">
<tr>
<td style="width:25%">
<div id="sidebar" style="overflow:auto;width:100%;height:100%;"></div>
</td>
<td style="width:75%">
<div id="map_canvas" style="width:100%;height:100%;"></div>
</td>
</tr>
</table>
<!--
<input style="position:absolute;z-index:1000;bottom:100px;left:400px;width:250px;"
type="text" value="Brighton Beach" name="address" id="address" />
<input style="position:absolute;z-index:1000;bottom:140px;left:400px;"
type="button" value="Geocode" onclick="geoCodeAddress();" />
<input style="position:absolute;z-index:1000;bottom:140px;left:480px;"
type="text" value="Milk" onclick="" />
<input style="position:absolute;z-index:1000;bottom:140px;left:600px;"
type="button" value="Go Milk!" onclick="" />
-->
<!--<div id="map_canvas" style="width:100%; height:100%"></div>-->
</body>
</html>