Upload Marker G Maps from While php

1

Opa,

I have a .php file with a while, where I get multiple records with addresses, this file is being called in an include in my index. The while prints several divs where within each has another div that is where the google map should be displayed, with the address marker.

The markers on the map are displayed perfectly if I start the javascript with fictitious coordinates placed in the index, but, how to indicate the real coordinates with data coming from a while and start the javascript, which are in an include? >

Javascript started in Index, beauty works.

google.maps.event.addDomListener(window, 'load', init);
function init() {
    var locations = [
                [40.6128,-73.9976, "images/pin-house.png", "estate-details-right-sidebar.html", "images/infobox-offer1.jpg", "Wall Street, Recife, BR", "R$120"]
            ];

            offersMapInit("offers-map",locations);
            mapInit(40.6128,-73.7903,"featured-map1","images/pin-house.png", false);
        }

The .php file, which is included in the index:

    <div class="featured-offers-container">
        <div class="owl-carousel" id="featured-offers-owl">
        <?php
            $data_atual = date("Y-m-d");

            $sql_lista=mysql_query(
                "
                    SELECT
                           cidade.name AS cidade_nome,
                           empresa.nome
                    FROM
                           cidade, empresa
                    WHERE
                           id_cidade = cidade.id AND
                           empresa.nome = 'blablabla'
                ");


            while($dados = mysql_fetch_array($sql_lista))
            {

            echo'
                <div class="featured-offer-col">
                    <div class="featured-offer-front">

                        <div class="featured-offer-text">
                            <h4 class="featured-offer-title">'.$dados['nome'] .'</h4>
                            '.$dados['cidade_nome'] .'

                            <p>'.$dados['descricao'] .'</p>
                        </div>
                    </div>

                    <div class="featured-offer-back">
                        <div id="featured-map1" class="featured-offer-map"></div>
                            <div class="button">
                            <a href="estate-details-right-sidebar.html" class="button-primary">
                                <span>read more</span>
                                <div class="button-triangle"></div>
                                <div class="button-triangle2"></div>
                                <div class="button-icon"><i class="fa fa-search"></i></div>
                            </a>
                        </div>
                    </div>

                </div>
            ';
        }
    ?>

        </div>
    </div>

The map should be displayed in the 'featured-map1' div, as are several records, the name of this div should be dynamic, how does it relate to the javascript initialization?

    
asked by anonymous 09.12.2015 / 19:50

1 answer

0

After so much thinking, I decided.

Within the while php, I create a div with the name 'list_map _'

Start JavaScript in another While in index this way

google.maps.event.addDomListener(window, 'load', init);
function init() {

    var locations = [

        <?php
            $coordenadas_sql = mysql_query(
            "
                SELECT
                       cidade.id AS id_cidade,
                       cidade.name AS cidade_nome,
                       empresa.nome
                FROM
                       cidade, empresa
                WHERE
                       id_cidade = cidade.id AND
                       empresa.nome = 'blablabla'
            ");
                while($coordenadas_dados = mysql_fetch_array($coordenadas_sql))
                {
                    echo '['.$coordenadas_dados['coordenada'].',"images/pin.png"],';
                }
        ?>
    ];
            <?php
                $coordenadas_sql = mysql_query(
                "
                SELECT
                       cidade.id AS id_cidade,
                       cidade.name AS cidade_nome,
                       empresa.nome
                FROM
                       cidade, empresa
                WHERE
                       id_cidade = cidade.id AND
                       empresa.nome = 'blablabla'
                ");
                    while($coordenadas_dados = mysql_fetch_array($coordenadas_sql))
                    {
                        echo 'mapInit('.$coordenadas_dados['coordenada'].',"list_map_'.$coordenadas_dados['id_cidade'].'","images/pin.png", false);';
                    }
            ?>
}

It works perfectly well

    
18.12.2015 / 21:14