-
Notifications
You must be signed in to change notification settings - Fork 0
/
StoreLocator.php
246 lines (210 loc) · 7.74 KB
/
StoreLocator.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
<?php session_start();
header("Cache-Control: max-age=300, must-revalidate");
if(isset($_COOKIE["name"])&&isset($_COOKIE["pwd"]))
{
$_SESSION["name"]=$_COOKIE["name"];
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&key=AIzaSyD0X4v7eqMFcWCR-VZAJwEMfb47id9IZao">
</script>
<style type="text/css">
span{
color: red;
}
#container,#map_canvas
{
width:100%;
height:600px; margin:10px;
padding :100px;
}
#sidebar{
width:100%;
height:600px;
margin:10px;
padding-left: 15px;
padding-right: 15px;
}
#submit
{
background:none repeat scroll 0% 0% #8FCB73;
display: inline-block;
width:100%;
padding: 5px 10px;
line-height: 1.05em;
box-shadow: 1px 2px 3px #8FCB73;
border-radius: 8px;
border: 1px solid #8FCB73;
text-decoration: none;
opacity: 0.9;
cursor: pointer;
color:white;
}
</style>
<script type="text/javascript">
var map;
$(document).ready(function () {
//draw a map centered at Empire State Building Newyork
var latlng = new google.maps.LatLng(19.014782, 72.841719);
var myOptions = {
zoom: 13,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
$("#submit").click(function(){
//Convert Address Into LatLng and Retrieve Address Near by
convertAddressToLatLng($("#txtAddress").val());
$('.result').show();
});
});
function convertAddressToLatLng(address){
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//Empty div before re-populating
$("#divStores").html('');
searchStores(results[0].geometry.location);
} else {
$("#divStores").html(getEmbedHTML('No Stores Found','',''));
}
});
}
function searchStores(location){
var latlng = new google.maps.LatLng(location.lat(),location.lng());
var myOptions = {
zoom: 13,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
//Marker at the address typed in
//var image = 'images/townhouse.png'
var marker = new google.maps.Marker({
position: latlng,
map: map,
//icon: image
});
//hard coded the radius to 10 miles, if you get the value from a field if required
var parameters = 'lat='+ location.lat() + '&lng=' + location.lng() + '&radius=10';
$.ajax({
type: "POST",
dataType: 'json',
url: "store_locator.php",
data: parameters,
success: function(msg) {
// alert(msg);
displayStores(msg);
},
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
}); /* $.ajax({ */
}
function displayStores(result){
if (result.length > 0){
for (i=0;i<result.length;i++){
//Append Store Address on Sidebar
var html = getEmbedHTML(i+1,result[i].name,result[i].address,result[i].distance);
$("#divStores").append(html);
//place a marker
// var image = 'images/number_' + parseInt(i+1) + '.png';
var latlng = new google.maps.LatLng(result[i].lat,result[i].lng);
var marker = new google.maps.Marker({
position: latlng,
map: map,
// icon: image
});
var msg = 'Location : ' + result[i].name + '<br/> ';
msg = msg + 'Address : ' + result[i].address + '<br/> ';
attachMessage(marker, msg);
}
} else {
$("#divStores").html(getEmbedHTML('No Stores Found','',''));
}
}
function attachMessage(marker, msg) {
var infowindow = new google.maps.InfoWindow({
content: msg,
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
}
function getEmbedHTML(seqno,name,address,distance) {
var strhtml = '<div class="result">';
strhtml = strhtml + '<label>' + name + '</label><br/>'
strhtml = strhtml + '<span>' + address + '<span><br/>'
strhtml = strhtml + '<span> Distance : ' + parseFloat(distance).toFixed(2) + ' miles<span><br/>'
strhtml = strhtml + '</div><div class="separator"></div>';
return strhtml;
}
</script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="icon" href="MediIcon.png">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="bootstrap.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<nav role="navigation" class="navbar navbar-inverse navbar-fixed-top" offset="500" tolerance="5">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="Home.php">MediFind</a>
</div>
<ul class="nav navbar-nav">
<li><a href=AboutUs.html">About Us</a></li>
<li><a href="StoreLocator.html">Search Stores</a></li>
<li><a href="#">Search Medicines</a></li>
<li><a href="#">Search Drugs</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<ul class="nav navbar-nav navbar-right">
<li><a href="userHome.php"><span class="glyphicon glyphicon-user"></span><?php echo $_SESSION["name"];?></a></li>
<li><a href="sessionunset.php"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li>
</ul>
</ul>
</div>
</nav><br><br>
<div class="row"><img src="MediFind.png">
<div class="page-header "><font size=60>MediFind</font></div>
<div class="panel-body">Your GateWay To World Of Quick Medicine Search!</div>
</div>
<div class="container" >
<div class="row shadow" style="background:#E3EDFA; margin:10px " >
<label for="Search">Search</label><br>
<input class="form-group" placeholder="Eg:Marol,Mumbai" type="text" name="search" id="txtAddress"><br><br>
<input type="submit" name="submit" id="submit" value="Submit">
</div>
<div id="map_canvas" class="shadow"></div>
<div id="sidebar" class="shadow">
<font face="Liberation Serif" size=20>Search Results:</font>
<div class="result" style="padding:10px;"></div>
<div class="separator"></div>
<div id="divStores">
<!--
<div class="row">
<label>Store 1<label><br/>
<span> Address Here<span>
</div>
<div class="separator"></div>
-->
</div>
</div>
</div>
</body>
</html>