Commit new added map folder

parent 664f0aa5
Pipeline #6243 failed with stages
<?php
$locations=array();
$uname="root";
$pass="";
$servername="localhost";
$dbname="pha";
$db=new mysqli($servername,$uname,$pass,$dbname);
//$number_of_rows = mysql_num_rows($db);
//echo $number_of_rows;
// SELECT med_hospital.hospital_name, med_hospital.h_lat, med_hospital.h_long
// FROM med_hospital
// INNER JOIN med_medicine ON med_hospital.hospital_name=med_medicine.med_hospital_name AND med_medicine.med_name = 'Vitamin E';
if( isset($_POST["submit"])) {
echo "Medicine Name - ". $_POST['medicine']. "<br />";
$query = $db->query("SELECT med_hospital.hospital_name, med_hospital.city, med_hospital.h_lat, med_hospital.h_long FROM med_hospital INNER JOIN med_medicine ON med_hospital.hospital_name=med_medicine.med_hospital_name AND med_medicine.med_name = '".$_POST["medicine"]."'");
while( $row = $query->fetch_assoc() ){
$name = $row['hospital_name'];
$longitude = $row['h_long'];
$latitude = $row['h_lat'];
$link=$row['city'];
$locations[]=array( 'name'=>$name, 'lat'=>$latitude, 'lng'=>$longitude, 'lnk'=>$link );
}
}else{
$query = $db->query("SELECT * FROM med_pharmacy");
while( $row = $query->fetch_assoc() ){
$name = $row['pharmacy_name'];
$longitude = $row['p_long'];
$latitude = $row['p_lat'];
$link=$row['city'];
$locations[]=array( 'name'=>$name, 'lat'=>$latitude, 'lng'=>$longitude, 'lnk'=>$link );
}
}
//echo $locations[0]['name'].": In stock: ".$locations[0]['lat'].", sold: ".$locations[0]['lng'].".<br>";
//echo $locations[1]['name'].": In stock: ".$locations[1]['lat'].", sold: ".$locations[1]['lng'].".<br>";
?>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyBkPHRLgrz1Uv_ctapXqGgEyFxTI_7aAtk&callback"></script>
<script type="text/javascript">
function getLocation(){
console.log("sjdkhksj")
}
var map;
var Markers = {};
var infowindow;
var locations = [
<?php for($i=0;$i<sizeof($locations);$i++){ $j=$i+1;?>
[
'AMC Service',
'<p><a href="<?php echo $locations[$i]['name'];?>"><?php echo $locations[$i]['name'];?></a></p>',
<?php echo $locations[$i]['lat'];?>,
<?php echo $locations[$i]['lng'];?>,
0
]<?php if($j!=sizeof($locations))echo ","; }?>
];
var origin = new google.maps.LatLng(locations[0][2], locations[0][3]);
function initialize() {
var mapOptions = {
zoom: 12,
center: origin
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
infowindow = new google.maps.InfoWindow();
for(i=0; i<locations.length; i++) {
var position = new google.maps.LatLng(locations[i][2], locations[i][3]);
var marker = new google.maps.Marker({
position: position,
map: map,
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][1]);
infowindow.setOptions({maxWidth: 200});
infowindow.open(map, marker);
}
}) (marker, i));
Markers[locations[i][4]] = marker;
}
locate(0);
}
function locate(marker_id) {
var myMarker = Markers[marker_id];
var markerPosition = myMarker.getPosition();
map.setCenter(markerPosition);
google.maps.event.trigger(myMarker, 'click');
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<body >
<form action="index.php" method="POST">
<label for="fname">Search Medicine:</label>
<input type="text" id="medicine" name="medicine"><br><br>
<input type="submit" name="submit" value="Submit">
</form>
<div style="width: 100%; height: 80%;" id="map-canvas"></div>
</body>
\ No newline at end of file
<?php
function geocode($address){
// url encode the address
$address = urlencode($address);
// google map geocode api url
$url = "http://maps.google.com/maps/api/geocode/json?address={$address}";
// get the json response from url
$resp_json = file_get_contents($url);
// decode the json response
$resp = json_decode($resp_json, true);
// response status will be 'OK', if able to geocode given address
if($resp['status']=='OK'){
//define empty array
$data_arr = array();
// get the important data
$data_arr['latitude'] = isset($resp['results'][0]['geometry']['location']['lat']) ? $resp['results'][0]['geometry']['location']['lat'] : '';
$data_arr['longitude'] = isset($resp['results'][0]['geometry']['location']['lng']) ? $resp['results'][0]['geometry']['location']['lng'] : '';
$data_arr['formatted_address'] = isset($resp['results'][0]['formatted_address']) ? $resp['results'][0]['formatted_address'] : '';
// verify if data is exist
if(!empty($data_arr) && !empty($data_arr['latitude']) && !empty($data_arr['longitude'])){
return $data_arr;
}else{
return false;
}
}else{
return false;
}
}
echo json_encode(geocode('denver'));
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment