MaxxxxiorS

geolokacja.php

Nov 24th, 2021
1,547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.34 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <title>Geolocation</title>
  5.     <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
  6.     <meta charset="utf-8">
  7.       <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
  8. <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
  9. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  10.     <style>
  11.        
  12. .button1 {
  13.     background-color: #4CAF50;
  14.     border: 2px;
  15.     color: white;
  16.     padding: 15px 32px;
  17.     text-align: center;
  18.     text-decoration: none;
  19.     /*display: inline-block;*/
  20.     font-size: 16px;
  21.     margin: 10px 2px;
  22.     cursor: pointer
  23. }
  24.             .button2 {
  25.     background-color: #d62e20;
  26.     border: none;
  27.     color: white;
  28.     padding: 15px 32px;
  29.     text-align: center;
  30.     text-decoration: none;
  31.     display: inline-block;
  32.     font-size: 16px;
  33.     margin: 4px 2px;
  34.     cursor: pointer;
  35.                 /*position: absolute;
  36.                 right: auto;*/
  37. }
  38.            
  39.                         .button3 {
  40.     background-color: #3520d6;
  41.     border: 2px;
  42.     color: white;
  43.     padding: 15px 32px;
  44.     text-align: center;
  45.     text-decoration: none;
  46.     display: inline-block;
  47.     font-size: 16px;
  48.     margin: 4px 2px;
  49.     cursor: pointer;
  50.                 /*position: absolute;
  51.                 right: auto;*/
  52.                
  53.                
  54. }
  55.  
  56.       /* Always set the map height explicitly to define the size of the div
  57.        * element that contains the map. */
  58.       #map {
  59.         height: 100%;
  60.       }
  61.       /* Optional: Makes the sample page fill the window. */
  62.       html, body {
  63.         height: 100%;
  64.         margin: 0;
  65.         padding: 0;
  66.       }
  67.     </style>
  68.   </head>
  69.   <body>
  70.  
  71.     <div class="user_logged_in">
  72.       <?php
  73.       include "login_klient/config.php";
  74.       // Create connection
  75.       $con = new mysqli($host, $user, $password, $dbname);
  76.       // Check connection
  77.       if ($con->connect_error) {
  78.         die("Connection failed: " . $con->connect_error);
  79.       }
  80.       // Check user login or not
  81.       if(!isset($_SESSION['uname'])){
  82.           header('Location: login_klient/login.php');
  83.       }
  84.  
  85.       $login=$_SESSION['uname'];
  86.  
  87.       echo "Aktualnie zalogowany jako: ".$login;
  88.       ?>
  89.  
  90.       <form class="wyloguj_container" method='post' action="">
  91.         <input class="wyloguj" type="submit" value="Wyloguj" name="but_logout">
  92.       </form>
  93.     </div>
  94. <?php
  95.   // logout
  96.     if(isset($_POST['but_logout'])){
  97.         session_destroy();
  98.         header('Location: home_klient.php');
  99.     }
  100. ?>
  101.  
  102.     <div class="w3-bar w3-white w3-large">
  103.   <a href="index.html" class="w3-bar-item w3-button w3-red w3-mobile"><i class="fa fa-home w3-margin-right"></i>Strona główna</a>
  104.  
  105. </div>
  106.        <div id="map" style="width:100%;height:400px"></div>
  107.     <form action="dodaj/dodaj1.php"  method="get">
  108.         <input type=text id="lng" name="lng" style="visibility: hidden; width:5%">
  109.     <input type=text id="lat" name="lat" style="visibility: hidden; width:5%">    
  110.            
  111.         <table>
  112.         <tr>
  113.            
  114.        
  115.             <td><a href="index.html" class="button2" >Anuluj</a></td>
  116.             <td><input type="submit" value="Zapisz" class="button1"></td>
  117.        
  118.             </tr>
  119.          </table>
  120.         </form>
  121.    
  122.    
  123.     <script>
  124.       // Note: This example requires that you consent to location sharing when
  125.       // prompted by your browser. If you see the error "The Geolocation service
  126.       // failed.", it means you probably did not give permission for the browser to
  127.       // locate you.
  128.       var map, infoWindow;
  129.       function initMap() {
  130.         map = new google.maps.Map(document.getElementById("map"), {
  131.  
  132.            
  133.            
  134.             center: {lat: -34.397, lng: 150.644},
  135.           zoom: 17
  136.         });
  137.         infoWindow = new google.maps.InfoWindow;
  138.  
  139.         // Try HTML5 geolocation.
  140.         if (navigator.geolocation) {
  141.           navigator.geolocation.getCurrentPosition(function(position) {
  142.             var pos = {
  143.               lat: position.coords.latitude,
  144.               lng: position.coords.longitude
  145.             };
  146. var lat=position.coords.latitude;
  147. var lng= position.coords.longitude;
  148.    document.getElementById("lng").value = lng;
  149.     document.getElementById("lat").value = lat;            
  150.             infoWindow.setPosition(pos);
  151.             infoWindow.setContent('Location found.');
  152.             infoWindow.open(map);
  153.             map.setCenter(pos);
  154.           }, function() {
  155.             handleLocationError(true, infoWindow, map.getCenter());
  156.           });
  157.         } else {
  158.           // Browser doesn't support Geolocation
  159.           handleLocationError(false, infoWindow, map.getCenter());
  160.         }
  161.       }
  162.  
  163.       function handleLocationError(browserHasGeolocation, infoWindow, pos) {
  164.         infoWindow.setPosition(pos);
  165.         infoWindow.setContent(browserHasGeolocation ?
  166.                               'Error: The Geolocation service failed.' :
  167.                               'Error: Your browser doesn\'t support geolocation.');
  168.         infoWindow.open(map);
  169.       }
  170.     </script>
  171.     <script async defer
  172.     src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDur8LxYqPiH6qTgVYZ_PC583tgAV9JJ04&callback=initMap">
  173.     </script>
  174.   </body>
  175. </html>
Advertisement
Add Comment
Please, Sign In to add comment