We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38506
    • 103 Posts
    Hello !

    I have a problem with googlemap ! I installed the V3 googlemap where the markers are automatically generated when a city is back in database. It works but it's really long (25 seconds to display)!Do you think it comes from queries? How can I do to make it go faster??

    Thank you !

    Snippet :

    <?php
    require('GoogleMapAPIv3.class.php');
    
                    $gmap = new GoogleMapAPI();
                    $gmap->setDivId('test1');
                    $gmap->setDirectionDivId('route');
                    $gmap->setCenter('Privas');
                    $gmap->setEnableWindowZoom(true);
    
                   // $gmap->setDisplayDirectionFields(true);
                  $gmap->setClusterer(false);
                    $gmap->setSize('385px','439px');
                    $gmap->setZoom(9);
                    $gmap->setLang('fr');
                    $gmap->setDefaultHideMarker(false);
                    // $gmap->addDirection('nantes','paris');
    
    
    				// $gmap->setIconSize(20,34);
                    $gmap->addArrayMarkerByAddress($coordtab,'cat1');
    
    
    
    $parent=$_GET['id'];
    $c = $modx->newQuery('modResource');
    	$c->where(array(
    	    $modx->resource->get('id'),
    	    ));
    
    $resources = $modx->getCollection('modResource',$c);
    
    $adressedep = $adressedep;
    $longitude = $longitude;
    $latitude = $latitude;
    $adressecode = $gmap->addMarkerByCoords($longitude,$latitude);
    
    foreach($resources as $resource){
      if ($resource->getTVValue("adresse_terrain")==""){
    
      }else{
    	$gmap->addMarkerByCoords($resource->getTVValue("latitude"),$resource->getTVValue("longitude"),$resource->getTVValue("adresse_terrain"),"<span style='color:#B70B01;font-weight:bold;'> Terrain à ".$resource->getTVValue("adresse_terrain")."</span>,<br/><img src='".$resource->getTVValue("ma_tv")."' style='width:70px; float:left; margin-right:5px;margin-top:10px;'/><p style='font-size:11px;width:255px;'>".$resource->getTVValue("description_terrain")."</p> <em>A partir de ".$resource->getTVValue("tarif")." € </em> <br/> <a name='bt_details' href='?id=".$resource->get('id')."' class='bt_terrain'>>> En savoir +</a><br/><a style='font-size:11px;' href='http://www.terrains-ardeche.fr/index.php?id=2&code_postal=Code+postal&Lieu=".$resource->getTVValue("adresse_terrain")."&sup=0&prix=A'>Voir tous les terrains à ".$resource->getTVValue("adresse_terrain")." </a><br/>");
      }
    }
    
                  $gmap->generate();
                    echo $gmap->getGoogleMap();
      • 42602
      • 81 Posts
      There is a flaw in your $c->where(), you don't define what the $modx->resource->get('id') should be compared against. This will cause an SQL error for sure. I would guess that as you are using getCollection, you want the where() to look like;

      $c->where(
          array('parent:=' => $modx->resource->get('id')
      );
      
      //also you can use $modx->resource->id to get the id of the resource (or you should be able to)
      


      Or (this came after good nights sleep to my mind. Skip the whole newQuery() and just use getCollection('modResource', array('parent:=' => $modx->resource->get('id')));
      The second parameter for getCollection() is criteria. [ed. note: dunnock last edited this post 13 years, 5 months ago.]