Google Maps does not load (php include)

0

The map worked normal on a separate page, but when included with the PHP include function it just does not work, it does not load anything. I have already checked the file paths and they are correct, JavaScript codes work.

include("module/map.php");

map.php:

<div class="panel panel-default">
    <div style="padding: 26px; padding-top: 6px;">
        <h3>Mapa</h3>
        Este é o mapa do servidor com informações reais atualizadas há 60 segundos ou menos, clique nos ícones para visualizar os detalhes. 
        Para um nível maior de zoom utilize a versão satélite do mapa.
    </div>

    <div style="width: 100%; height: 80%;" id="divMap"></div>
</div>

<script src="http://maps.google.com/maps/api/js?key=AIzaSyC9-DDWI5_Pcqg2HsrL247PACWqTPmZDlI"></script><scriptsrc="../include/SanMap/js/SanMap.min.js"></script>

<script>
    //Tipos
    var mapType = new SanMapType(0, 1, function (zoom, x, y) {
        return x == -1 && y == -1
        ? "../include/SanMap/tiles/map.outer.png" 
        : "../include/SanMap/tiles/map." + zoom + "." + x + "." + y + ".png";
    });

    var satType = new SanMapType(0, 3, function (zoom, x, y) {
        return x == -1 && y == -1
        ? "../include/SanMap/tiles/sat.outer.png" 
        : "../include/SanMap/tiles/sat." + zoom + "." + x + "." + y + ".jpeg";
    });

    //Mapa
    var map = SanMap.createMap(document.getElementById('divMap'), 
        {'Mapa': mapType, 'Satélite': satType}, 2, null, false, 'Mapa');


    <?php
        function GetTeamName2($team)
        {
            $Team = array(
            0 => array('tNome' => "USA", 'tSkin' => 287, 'tCor' => 0x009DFF, 'tGZCor' => 0x0000FF, 'tGTCor' => "~b~~h~", 'tGZ' => 0, 'tSP' => array(0 => -320.2578, 1 => 2719.4568, 2 => 62.6875, 3 => 202.8093)),
            1 => array('tNome' => "Rússia", 'tSkin' => 285, 'tCor' => 0xFF4800, 'tGZCor' => 0xFF4800, 'tGTCor' => "~r~~h~", 'tGZ' => 0, 'tSP' => array(0 => -136.1105, 1 => 1116.5667, 2 => 20.1966, 3 => 0.0)),
            2 => array('tNome' => "Europa", 'tSkin' => 73, 'tCor' => 0x00FF00, 'tGZCor' => 0x00FF00, 'tGTCor' => "~g~~h~", 'tGZ' => 0, 'tSP' => array(0 => -1408.5350, 1 => 2672.5684, 2 => 71.5672, 3 => 153.8131)),
            3 => array('tNome' => "Iraque", 'tSkin' => 122, 'tCor' => 0xFFBB00, 'tGZCor' => 0xFFBB00, 'tGTCor' => "~y~", 'tGZ' => 0, 'tSP' => array(0 => -754.8708, 1 => 1590.7395, 2 => 26.9609, 3 => 0.0)),
            4 => array('tNome' => "Austrália", 'tSkin' => 206, 'tCor' => 0xF700FF, 'tGZCor' => 0xF700FF, 'tGTCor' => "~p~", 'tGZ' => 0, 'tSP' => array(0 => -754.8708, 1 => 1590.7395, 2 => 26.9609, 3 => 0.0)),
            5 => array('tNome' => "Mercenário", 'tSkin' => 137, 'tCor' => 0xFFFFFF, 'tGZCor' => 0xFFFFFF, 'tGTCor' => "~w~~h~", 'tGZ' => 0, 'tSP' => array(0 => -754.8708, 1 => 1590.7395, 2 => 26.9609, 3 => 0.0))
            );
            return $Team[$team]['tNome'];
        }

        function GetTeamGZColor($team)
        {
            $Team = array(
            0 => array('tNome' => "USA", 'tSkin' => 287, 'tCor' => 0x009DFF, 'tGZCor' => 0x0000FF, 'tGTCor' => "~b~~h~", 'tGZ' => 0, 'tSP' => array(0 => -320.2578, 1 => 2719.4568, 2 => 62.6875, 3 => 202.8093)),
            1 => array('tNome' => "Rússia", 'tSkin' => 285, 'tCor' => 0xFF4800, 'tGZCor' => 0xFF4800, 'tGTCor' => "~r~~h~", 'tGZ' => 0, 'tSP' => array(0 => -136.1105, 1 => 1116.5667, 2 => 20.1966, 3 => 0.0)),
            2 => array('tNome' => "Europa", 'tSkin' => 73, 'tCor' => 0x00FF00, 'tGZCor' => 0x00FF00, 'tGTCor' => "~g~~h~", 'tGZ' => 0, 'tSP' => array(0 => -1408.5350, 1 => 2672.5684, 2 => 71.5672, 3 => 153.8131)),
            3 => array('tNome' => "Iraque", 'tSkin' => 122, 'tCor' => 0xFFBB00, 'tGZCor' => 0xFFBB00, 'tGTCor' => "~y~", 'tGZ' => 0, 'tSP' => array(0 => -754.8708, 1 => 1590.7395, 2 => 26.9609, 3 => 0.0)),
            4 => array('tNome' => "Austrália", 'tSkin' => 206, 'tCor' => 0xF700FF, 'tGZCor' => 0xF700FF, 'tGTCor' => "~p~", 'tGZ' => 0, 'tSP' => array(0 => -754.8708, 1 => 1590.7395, 2 => 26.9609, 3 => 0.0)),
            5 => array('tNome' => "Mercenário", 'tSkin' => 137, 'tCor' => 0xFFFFFF, 'tGZCor' => 0xFFFFFF, 'tGTCor' => "~w~~h~", 'tGZ' => 0, 'tSP' => array(0 => -754.8708, 1 => 1590.7395, 2 => 26.9609, 3 => 0.0))
            );
            return sprintf("%06X", $Team[$team]['tGZCor']);
        }

        $query = mysqli_query($conectar, "SELECT * FROM gangzones");
        $row = 0;
        while($dados = mysqli_fetch_assoc($query))
        {
            $pl = mysqli_fetch_assoc(mysqli_query($conectar, "SELECT Nome FROM contas WHERE ID=$dados[Dominador]"));
            $row = $dados['ID'];
            echo "
            var flagInfoWindow".$row." = new google.maps.InfoWindow({
                content: '<h3>$dados[Nome]</h3><p>Controlado pela equipe <b>".GetTeamName2($dados['Equipe'])."</b></p>'
            });
            var flagMarker".$row." = new google.maps.Marker({
                position: SanMap.getLatLngFromPos($dados[cpX], $dados[cpY]),
                map: map,
                icon: '../include/SanMap/icons/red_flag.gif'
            });
            google.maps.event.addListener(flagMarker".$row.", 'click', function() {
                map.setCenter(flagMarker".$row.".position);
                flagInfoWindow".$row.".open(map,flagMarker".$row.");
            });
            ";

            $Xfrom = $dados['minX'];
            $Yfrom = $dados['minY'];
            $Xto = $dados['maxX'];
            $Yto = $dados['maxY'];
            $color = GetTeamGZColor($dados['Equipe']);

            echo "
            var pfrom".$row." = SanMap.getLatLngFromPos($Xfrom, $Yfrom);
            var pto".$row." = SanMap.getLatLngFromPos($Xto, $Yto);

            new google.maps.Rectangle
            (
                {           
                    strokeColor: '#FF0000',
                    strokeOpacity: 0.8,
                    strokeWeight: 0,
                    fillColor: '#".$color."',
                    fillOpacity: 0.35,
                    map: map,
                    bounds:
                    {
                        north: pto".$row.".lat(), //X to
                        south: pfrom".$row.".lat(), //X from
                        east: pto".$row.".lng(), //Y to
                        west: pfrom".$row.".lng() //Y from
                    }
                }
            );
            ";
        }
        $query = mysqli_query($conectar, "SELECT * FROM contas WHERE Online=1 AND ".time()." - OnlineT < 300");
        $row = 0;
        while($dados = mysqli_fetch_assoc($query))
        {
            echo "
            var playerInfoWindow".$row." = new google.maps.InfoWindow({
                content: '<h5>$dados[Nome]</h5><p>Score: <b>$dados[Score]</b><br><a href=\'perfil?p=$dados[ID]\' target=\'_blank\'>Ver perfil</a></p>'
            });
            var playerMarker".$row." = new google.maps.Marker({
                position: SanMap.getLatLngFromPos( $dados[X] , $dados[Y] ),
                map: map,
                icon: '../include/SanMap/icons/player.gif'
            });
            google.maps.event.addListener(playerMarker".$row.", 'click', function() {
                map.setCenter(playerMarker".$row.".position);
                playerInfoWindow".$row.".open(map,playerMarker".$row.");
            });
            ";
            $row++;
        }

        if(isset($_GET['gz']))
        {
            $_GET['gz'] = (int) $_GET['gz'];
            echo "
            map.setCenter(flagMarker".$_GET['gz'].".position);
            flagInfoWindow".$_GET['gz'].".open(map,flagMarker".$_GET['gz'].");
            ";
        }
    ?>

    /*
    //Indicador de posição (alert onclick)
    google.maps.event.addListener(map, 'click', function(event) {
        var pos = SanMap.getPosFromLatLng(event.latLng);
        alert(pos.x + "," + pos.y);
    });
    */

</script>

Structure:

cod/ucp/module/map.php    Mapa
cod/ucp/index.php         Arquivo onde é incluído o mapa
cod/include               Diretório de includes

Old structure (where the map worked):

cod/ucp/map.php     Mapa
cod/include         Diretório de includes
    
asked by anonymous 18.08.2017 / 01:41

1 answer

0

Problem solved.

Failed to specify width and height in pixels in div where the map loads.

    
18.08.2017 / 21:16