Load Marker G Maps from While php

Asked

Viewed 66 times

1

Opa,

I have a file . php with a while, where I return several records with addresses, this file is being called in a include in my index. while prints multiple Ivs where inside each has another div which is where the google map should be displayed, with the address Marker.

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

Javascript started on Index, works beauty.

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 div 'featured-map1', as there are several records, the name of this div I believe should be dynamic, as it relates to the javascript initialization?

  • Put in the code, it would be easier to understand.

1 answer

0

After all that thinking, I decided.

Inside while php, create a div named 'list_map_'

Start Javascript on another While on 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);';
                    }
            ?>
}

Works perfectly well

Browser other questions tagged

You are not signed in. Login or sign up in order to post.