Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Aiuto per store locator

    Ciao ragazzi sto impazzendo con questo script. Come test sto replicando questo store Locator che si trova quihttps://pgtools.proximityitalia.com/Boots/StoreLocator/

    Praticamente lo store Locator di questo link accetta in entrata il cap oppure la città/provincia e restituisce sulla mappa i vari markers. Il mio problema è che io all'interno del mio db non possiedo le coordinate gps dei vari siti che devo mostrare a video. Ho visto però che il codice permette di poterle calcolare direttamente dalla via però non so proprio cosa modificare. Qualcuno che capisce un pò di javascript potrebbe aiutarmi please.

    Ecco i miei tre file:

    map_function.js



    codice:
        function searchLocationsNear(cap,prov,city) {
    
               var searchParams='';
    
               if (typeof(cap) != 'undefined'){
                   searchParams ='?cap=' + cap;
               }
               //if (typeof(prov) != 'undefined'){
               //    searchParams ='?prov=' + prov;
               //}
    
               if (typeof(city) != 'undefined'){
                   if(city=='--'){
                       searchParams ='?prov=' + prov;
                   }else{
                        searchParams ='?city=' + city;
                   }
               }
    
    	 var sidebar = document.getElementById('sidebar');
    	 sidebar.innerHTML = "";
    	 sidebar.style.overflow='auto';
    
    	 var div = document.createElement('div');
      	 div.style.margin='10px';
      	 div.innerHTML = '<img src=\'img/loading.gif\' border=\'0\'>';
      	 sidebar.appendChild(div);
    		//alert('where: ' + where);
    
         //var radius = document.getElementById('radiusSelect').value;
         //var searchUrl = 'phpsqlsearch_genxml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;
         //var searchUrl = 'genXML.php?cap=' + cap;
         var searchUrl = 'genXML.php'+searchParams;
         //alert(searchUrl);
         GDownloadUrl(searchUrl, function(data) {
           var xml = GXml.parse(data);
           var markers = xml.documentElement.getElementsByTagName('marker');
           var rootmarkers = xml.getElementsByTagName("markers");
    
           for (var i = 0; i < rootmarkers.length; i++) {
               var centerLat = rootmarkers[i].getAttribute("centerLat");
               var centerLng = rootmarkers[i].getAttribute("centerLng");
           }
    
           map.clearOverlays();
    
    
           sidebar.innerHTML = '';
    
           //alert('searchUrl: ' + searchUrl);
           if (markers.length == 0) {
        	 var div = document.createElement('div');
        	 div.style.margin='10px';
        	 div.innerHTML = 'La ricerca non ha prodotto risultati';
        	 sidebar.appendChild(div);
             //sidebar.innerHTML = 'No results found.';
             //map.setCenter(new GLatLng(centerLat,centerLng), 5);
             return;
           }
    
           var bounds = new GLatLngBounds();
           for (i = 0; i < markers.length; i++) {
             //if ((markers[i].getAttribute('lat')!="") && (markers[i].getAttribute('lng')!="")){
    	         var name = markers[i].getAttribute('name');
    	         var address = markers[i].getAttribute('address');
    	         var city = markers[i].getAttribute('city');
    	         var prov = markers[i].getAttribute('prov');
    	         var phone = markers[i].getAttribute('phone');
                     var feature = markers[i].getAttribute('feature');
    	         var distance = parseFloat(markers[i].getAttribute('distance'));
    //                 if ((markers[i].getAttribute('lat')=="") || (markers[i].getAttribute('lng')=="")){
    //                     geocoder.getLatLng(address+", "+city, function(latlng) {
    //
    //                           if (latlng) {
                                 //alert(latlng)
    //                             var marker = createMarker(latlng, name, address, city, prov, phone,feature);
    //                           }
    //                     });
    //                 } else {
    //                     var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),parseFloat(markers[i].getAttribute('lng')));
    //                     var marker = createMarker(point, name, address, city, prov, phone,feature);
    //                 }
    //
    //                 
    //                 if ((markers[i].getAttribute('lat')!="") || (markers[i].getAttribute('lng')!="")){
    //                 var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),parseFloat(markers[i].getAttribute('lng')));
    //                     var marker = createMarker(point, name, address, city, prov, phone,feature);
    //
    
                    var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),parseFloat(markers[i].getAttribute('lng')));
                    var marker = createMarker(point, name, address, city, prov, phone,feature);
    	         
    	      	 map.addOverlay(marker);
    	         var sidebarEntry = createSidebarEntry(marker, name, address, distance, city, prov, phone,feature);
    	         sidebar.appendChild(sidebarEntry);
    	         bounds.extend(point);
                     //}
             }
           //}
           map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
         });
       }
    All'interno della funzione searchLocationsNear dopo il richamo al mio file genXML.php vi sono delle righe commentate. Ho provato di tutto , ma nn riesco a farmi stampare i vari markers.
    Ho provato a togliere i vari commenti che vi sono alla fine del file.Quindi se lat e lng sono vuoti lui li calcola e li stampa corretti (alert (latlng) )ma non mi visualizza nulla.

    Qui anche il codice di genXMLphp

    codice:
     
    
    <?php
    header("Content-type: text/xml");
    require("phpsqlsearch_dbinfo.php");
    
    function parseToXML($htmlStr) 
    { 
    $xmlStr=str_replace('<','&lt;',$htmlStr); 
    $xmlStr=str_replace('>','&gt;',$xmlStr); 
    $xmlStr=str_replace('"','&quot;',$xmlStr); 
    $xmlStr=str_replace("'",'&#39;',$xmlStr); 
    $xmlStr=str_replace("&",'&amp;',$xmlStr); 
    return $xmlStr; 
    } 
    
    // Get parameters from URL
    //$cap = $_GET["cap"];
    //$prov = $_GET["prov"];
    $city = $_GET["city"];
    
    // Opens a connection to a MySQL server
    $connection=mysql_connect ("localhost", $username, $password);
    if (!$connection) {
      die('Not connected : ' . mysql_error());
    }
    
    // Set the active MySQL database
    $db_selected = mysql_select_db($database, $connection);
    if (!$db_selected) {
      die ('Can\'t use db : ' . mysql_error());
    }
    
    // Select all the rows in the markers table
    $query = "SELECT * FROM markers WHERE city='$city'";
    $result = mysql_query($query);
    if (!$result) {
      die('Invalid query: ' . mysql_error());
    }
    
    // Start XML file, echo parent node
    echo "<markers>\n";
    // Iterate through the rows, printing XML nodes for each
    while ($row = @mysql_fetch_assoc($result)){
      // ADD TO XML DOCUMENT NODE
      echo '<marker ';
      echo 'name="' . parseToXML($row['name']) . '" ';
      echo 'address="' . parseToXML($row['address']) . '" ';
      echo 'city="' . $row['city'] . '" ';
      echo 'prov="' . $row['prov'] . '" ';
      echo 'feature="' . $row['feature'] . '" ';
      echo 'lat="" ';
      echo 'lng="" ';
      echo "/>\n";
    }
    
    // End XML file
    echo "</markers>\n";
    
    ?>

  2. #2
    Ciao, nessuno sa proprio quale potrebbe essere il problema?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.