Maximum limit Google Maps bookmarks

Asked

Viewed 1,084 times

2

I have the application below, which adds markers on the map according to the past addresses, but it seems to me that you have a maximum limit. It only scores 10 points, but there are more than 10 addresses passed. Would anyone know why and how I solve this case ? I need a slightly higher limit. Is there a way to get it ? And how ?

Code:

<?php
include_once 'connection_open.php';
include_once 'DAO/RoteiroDAO.php';
include_once 'controller/RoteiroCont.php';
include_once 'model/Roteiro.php';

$roteiro = new RoteiroControle($conn);

$romaneio = filter_input(INPUT_POST, 'romaneio');

if ($romaneio) {
    $romaneio = $romaneio;
} else {
    $romaneio = 'null';
}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Roteiros</title>
        <script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript"></script>
        <script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
        <link href="css/main.css" rel="stylesheet" />
    </head>
    <body>
        <div class="container_12">
            <form action="index" method="POST">
                <fieldset>
                    <label>Romaneio:</label>
                    <input type="text" name="romaneio" value="<?php
                    if ($romaneio == 'null') {
                        echo '';
                    } else {
                        echo $romaneio;
                    }
                    ?>"/>
                    <label>Placa:</label>
                    <input type="text" name= "placa" value=""/>
                    <br>
                    <button type="submit">Filtrar</button>
                </fieldset>
            </form>

            <?php if ($romaneio != 'null') { ?>
                <table class="tableModif">
                    <thead>
                        <tr>
                            <th>Romaneio</th>
                            <th>Placa</th>
                            <th>Cte</th>
                            <th>Data Saida</th>
                            <th>Endereço</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($roteiro->ListaRoteiro($romaneio) as $dados) { ?>
                            <tr>
                                <td><?php echo $dados->getRomaneio(); ?></td>
                                <td><?php echo $dados->getPlaca(); ?></td>
                                <td><?php echo $dados->getCte(); ?></td>
                                <td><?php echo ($roteiro->FormataData($dados->getDtSaidaRomaneio())); ?></td>
                                <td><?php echo $dados->getEndereco(); ?></td>
                            </tr>
                        <?php } ?>
                    </tbody>
                </table>
            <?php } ?>

            <br>

            <div class="map" id="map" style="height: 500px; width: 100%;"></div>

            <br><br>

        </div>

        <script src="js/gmaps.js" type="text/javascript"></script>
        <script src="js/markers.js" type="text/javascript"></script>    
        <script>
            $(function () {

                //Definir o centro do mapa [endereço + elm div]
                initMap('Av. Paulista, 500, São Paulo, SP', 'map');

                <?php foreach ($roteiro->ListaRoteiro($romaneio) as $dados) { ?>

                    //Adicionar marcadores  [endereço + descricao html)
                    addMarker('<?php echo $dados->getEndereco(); ?>', '<?php echo $dados->getEndereco(); ?>');

                <?php } ?>
            })
        </script>
    </body>
</html>

The function addMarker that I call the archive markers.js that’s the one:

function addMarker(address, html){
    GMaps.geocode({
        address: address,
        callback: function (results, status) {
            if (status == 'OK') {
                var latlng = results[0].geometry.location;
                if (html == "") {
                    html = address;
                }
                lat = latlng.lat();
                lng = latlng.lng();
                var icon = "icons/m1.png";
                map.addMarker({
                    lat: lat,
                    lng: lng,
                    icon: icon,
                    //title: address,
                    infoWindow: {
                        content: html
                    }
                });
            }
        }
    })
}

Exit:

Of these below shows on the map only the first 10 addresses.

$(function () {

  initMap('Av. Paulista, 500, São Paulo, SP', 'map');

  addMarker('RUA SAO FRANCISCO DE SALLES 191 Ap 96 - CENTRO - DIADEMA - SP', '');                
  addMarker('RUA PROFESSOR EVANDRO CAIAFA ESQUIVEL 235 Apto 5 - CENTRO - DIADEMA - SP', '');              
  addMarker('TUPIRITAMA 353 - AMERICANOPOLIS - SAO PAULO - SP', '');
  addMarker('BAEPENDY 595 - CAMPANARIO - DIADEMA - SP', '');
  addMarker('AV MOINHO FABRINI 339 - INDEPENDENCIA - SAO BERNARDO DO CAMPO - SP', '');
  addMarker('AVENIDA PIRAPORINHA 540 Bl yel - PLANALTO - SAO BERNARDO DO CAMPO - SP', '');
  addMarker('AVENIDA WINSTON CHURCHILL 1477 Cond - RUDGE RAMOS - SAO BERNARDO DO CAMPO - SP', '');
  addMarker('RUA SARMENTO DE BEIRES- 421  - JARDIM PORTUGAL - SAO BERNARDO DO CAMPO - SP', '');
  addMarker('RUA PAPA PAULO VI-200  - SANTA TEREZINHA - SAO BERNARDO DO CAMPO - SP', '');
  addMarker('RUA SERRA DO PILAR-129  - COOPERATIVA - SAO BERNARDO DO CAMPO - SP', '');
  addMarker('AVENIDA SENADOR VERGUEIRO 1310 Apto - PINHEIROS - SAO PAULO - SP', '');
  addMarker('RUA LEILA GONCALVES-481  - ANCHIETA - SAO BERNARDO DO CAMPO - SP', '');
  addMarker('AVENIDA GETULIO VARGAS 648 Casa c - VILA BAETA NEVES - SAO BERNARDO DO CAMPO - SP', '');
  addMarker('RUA PAULINO DE ABREU 039 casa 3 - FERRAZOPOLIS - SAO BERNARDO DO CAMPO - SP', '');
  addMarker('AVENIDA CAMINHO DO MAR 2427 Apt. - RUDGE RAMOS - SAO BERNARDO DO CAMPO - SP', '');
  addMarker('AV PEREIRA BARRETO 2444 - TAMBORE - BARUERI - SP', '');
  addMarker('RUA JORGE CHAMMAS-272  - VILA AMERICA - SANTO ANDRE - SP', '');
  addMarker('MELVIN JONES-74  - VILA BASTOS - SANTO ANDRE - SP', '');
  addMarker('RUA ADOLFO BASTOS 1239 sala - VILA BASTOS - SANTO ANDRE - SP', '');
});
  • It is the limit of the Google Maps API itself.

  • There’s an answer on that link, that the guy put 250 tags http://stackoverflow.com/questions/3059044/google-maps-js-api-v3-simple-multiple-marker-example - there’s no way to adapt my code to that ?

  • I use google maps api and present how many markers come, no limits, I didn’t need to set anything. Are you sure you have more than 10 results even? You can also put a key to see if this is the problem <script src="http://maps.google.com/maps/api/js?key=SUA_CHAVE_AQUI"></script>.

  • Worse than I’m sure, because the output has more than 10 addresses. And I’ve used with the key and in the same.

  • If you give a console.log(status) and console.log(result) inside callback and before if(status == 'OK') from Function addMarker it prints the 10 results or all?

  • @André Vicente Continues to print all the results. But on the map only marks the top 10.

  • 1

    Guy takes a test, tries to create a delay between creating the points, you can use the setTimeout and gradually increase the time so that they do not start together, example: setTimeout(Function() {addMarker('RUA SAO FRANCISCO', ''); }, 200); hence the next one instead of 200 you put 400 and so it goes...

  • @Juniornunes Opa, it worked. Setei manual, it worked by giving a delay on each one. How do I now dynamic as it is in my code ?

  • @Kevin. F I need to know in which part you call and feeds the functions addMarker, can post the code?

  • @Juniornunes I feed there in the first part of the code I posted just scroll down.

  • All right, I’ll answer!

Show 6 more comments

2 answers

3


From the looks of it the Google API limits markups when trying to do several at a time.

You’ll have to put a delay between each call of the addMarker function, you can take advantage of your loop to do this, like this:

<?php foreach ($roteiro->ListaRoteiro($romaneio) as $i => $dados) { ?>

      setTimeout(function() {
          addMarker('<?php echo $dados->getEndereco(); ?>', '<?php echo $dados->getEndereco(); ?>');
      }, 400*parseInt("<?php echo $i; ?>"));

<?php } ?>

NOTE: If you have many points, and it takes a long time to load you can try to decrease the delay by changing the 200 in setTimeout, but test to make sure that you are loading all smoothly.

You can test this alternative too that will put a delay of 10 in 10 function calls:

<?php foreach ($roteiro->ListaRoteiro($romaneio) as $i => $dados) { ?>

      setTimeout(function() {
          addMarker('<?php echo $dados->getEndereco(); ?>', '<?php echo $dados->getEndereco(); ?>');
      }, 400*parseInt("<?php echo floor($i/10); ?>"));

<?php } ?>
  • 1

    It worked, in my case it’s 18 points if I leave the setTimeout in 200 it shows only 12 points, I had to increase to 400. For now it is feasible I believe that does not exceed 20 points.

  • I think the delay has to be a little bit bigger, I’ll edit the answer!

  • 10 what? seconds or milliseconds, in your code is 400 milliseconds, then from 400ms in 400ms it calls the function with the new data. If you put 10ms on 10ms, it will get very fast and it will blow.

  • It works only that I need to increase the milliseconds even more. With 400 does not show everything.

  • I understand, make this last modification: floor($i/10), and then you calculate what will be worth most for the execution of your program

0

Young man, comment on callback’s IF and see if the result remains the same. If you display all entries, let us know that we try to resolve from there.

  //    if (status == 'OK') {
            var latlng = results[0].geometry.location;
            if (html == "") {
                html = address;
            }
            lat = latlng.lat();
            lng = latlng.lng();
            var icon = "icons/m1.png";
            map.addMarker({
                lat: lat,
                lng: lng,
                icon: icon,
                //title: address,
                infoWindow: {
                    content: html
                }
            });
        //}

  • The result remains the same.

Browser other questions tagged

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