/
weather.php
65 lines (55 loc) · 1.51 KB
/
weather.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
<!--
* Author : Rohit Shakya
* Date : June-2020
* Editor : Sublime text
* Local server: Xampp
* Title : Blog posting site featuring with Weather and News report
* Version: v5.6
-->
<?php
session_start();
if(!isset($_SESSION['username']))
{
header('Location: home1.html');
}
include_once 'nav.php';
?>
<section><br><br>
<!--Search Bar Form-->
<!--Make sure the form has the autocomplete function switched off:-->
<form autocomplete="off" action="/weathersearch.php">
<div class="autocomplete" style="width:300px;">
<input id="myInput" type="text" name="myCountry" placeholder="Enter a City Name">
</div>
<input type="submit">
</form><br>
<!--form over-->
<!--nav bar complete-->
<strong>
<?php
$apiKey = "231a533e913c7e004f7ea56e36a67d83";
$cityId = 1261481;
$googleApiUrl = "http://api.openweathermap.org/data/2.5/weather?id=" . $cityId . "&lang=en&units=metric&APPID=" . $apiKey;
//search bar file added here to reduce code
include_once'searchbox.php';?>
<br><strong>
<button onclick="getLocation()">Get your coordinates</button><br>
<p id="demo"></p></strong>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
</section>
<!--section over-->
</body>
</html>