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

    Integrare javascript in modulo Joomla per Google maps

    ciao a tutti,
    ho un sito in (CMS) Joomla che usa un modulo per mostrare i markers relativi alle coordinate degli articoli inseriti ( con Sobi2 di sigsiu.net ) su una mappa di Google ( con api V2 ).
    Ho trovato in rete un javascript che usa Api V3 per fare il geocoding della posizione locale dell'utente; Vorrei integrare le due cose per centrare la mappa mostrata dal modulo appunto.

    Ho provato a sistemare il file.php del modulo in questione alla mappa in test, ma ancora la mappa viene caricata prima che il popup del geocoding venga cliccato. mettendo un alert mi restituisce come null tralaltro la var coordinate.. cioè il javascript non passa alla mappa del mio modulo la coppia locale delle coordinate.

    come posso fare secondo voi per far eseguire lo script prima del caricamento della mappa, e per passare il valore delle coordinate in maniera esatta??
    grazie, Luca.

    Codice PHP:
    <?php $documento =& JFactory::getDocument();  $documento->addScript('http://code.google.com/apis/gears/gears_init.js');  $javascript =" var coordinate = null;     function getLocale(){       if ( navigator ) {         if ( navigator.userLanguage ) {             return navigator.userLanguage.toLowerCase();         }         else if ( navigator.language ) {             return navigator.language.toLowerCase();         }         else if ( navigator.browserLanguage ) {             return navigator.browserLanguage.toLowerCase();         }         else if ( navigator.systemLanguage ) {             return navigator.systemLanguage.toLowerCase();         }       }       return \"unknown\";     }      var locales = new Object();     locales[\"en-gb\"] = {lat:54.559322587438636, lng:-4.1748046875, location:\"United Kingdom\"};     locales[\"en-us\"] = {lat:38.41055825094609, lng:-100.37109375, location:\"USA\"};     // TODO - more locales      function TryGoogleLoader(){       if (google.loader.ClientLocation != null) {         var address = google.loader.ClientLocation.address;         var yourLocation = address.city + \", \" + address.region + \", \" + address.country;          document.getElementById(\"location\").innerHTML = \"Your location (using Google loader) is \" + yourLocation;         var latLong = new google.maps.LatLng(google.loader.ClientLocation.latitude,           google.loader.ClientLocation.longitude);         //showMap(latLong, 12);         coordinate = latLong;         }         else {         // map locale to location         var locale = getLocale();         if (locales[locale] != null) {           var latLong = new google.maps.LatLng(locales[locale].lat, locales[locale].lng);           document.getElementById(\"location\").innerHTML =             \"Guessing your location based on your locale - \" + locales[locale].location;           //showMap(latLong, 5);           coordinate = latLong;         }         else {           document.getElementById(\"location\").innerHTML = \"Your location can not be found - locale is \" + locale;         }       }     }      function TryGoogleGears(){       if (google.gears) {         // Try Google Gears Geolocation         var geo = google.gears.factory.create('beta.geolocation');         geo.getCurrentPosition(function(position) {           var latLong = new google.maps.LatLng(position.latitude, position.longitude);           document.getElementById(\"location\").innerHTML = \"Found location via Google Gears\";           //showMap(latLong, 15);           coordinate = latLong;         }, function() {           TryGoogleLoader();         });       }       else         TryGoogleLoader();     }     "$documento->addScriptDeclaration($javascript);     \\* @packageSobi2  \\* =================================================== \\ * @author  \\* NameSigrid Radek SuskiSigsiu.NET GmbH  \\* Emailsobi[at]sigsiu.net    \\......bla bla bla.....  $config->getGoogleMaps(); $baseAddresse         $params->get('baseAddresse''http://maps.google.com'); $width                 $params->get('width'); $height             $params->get('height'); $mapControl         $params->get('MapControl'); $mapTypeControl     $params->get('MapTypeControl'); $overviewMapControl $params->get('OverviewMapControl',1); $doubleClickZoom     $params->get('DoubleClickZoom',1); $mapTypeOnStart     $params->get('MapTypeOnStart''G_NORMAL_MAP'); $centerPointLat     $params->get('centerPointLat',"0.0" ); $centerPointLat str_replace(',','.',$centerPointLat ); $centerPointLong     $params->get('centerPointLong'"0.0" ); $centerPointLong str_replace(',','.',$centerPointLong ); $mapsZoom             $params->get('MapsZoom'); $hybrid_label        $params->get('hybrid_label'"Labels"); $Automatic            $params->get('Automatic'0); $showEmpty          $params->get('showEmpty'1); $debugMode          $params->get('debugMode'0);  if (($catId 1) && ($inSobi)) { //nur wenn in einer cat sonst net     if( strstr( $catsCenterPoints, "\n" ) ) {         $catsCenterPoints = explode( "\n", $catsCenterPoints );     }     elseif( strstr( $catsCenterPoints, "\r" ) ) {         $catsCenterPoints = explode( "\r", $catsCenterPoints );     }     else {         $catsCenterPoints = array($catsCenterPoints);     }      if( is_array( $catsCenterPoints ) && !empty( $catsCenterPoints ) ) {         foreach ( $catsCenterPoints as $point ) {             $point = trim( $point );             $point = explode( ":", $point );             if( trim( $point[0] ) == $catId ) {                 if( ( isset( $point[1] ) && is_numeric( $point[1] ) ) && isset( $point[2] ) && is_numeric( $point[2] ) ) {                     $centerPointLat = floatval( $point[1] );                     $centerPointLong = floatval( $point[2] );                     if( isset( $point[3] ) && is_numeric( $point[3] ) ) {                         $mapsZoom = intval( $point[3] );                     }                 }                 break;             }         }     } }  if( !( is_numeric( $centerPointLat ) ) || !( is_numeric( $centerPointLong ) ) ) {     $centerPointLat = "0.0";     $centerPointLong = "0.0"; }  \\ ....bla bla bla...      if(empty($sobiItems)) { //keine Einträge mit Koordinaten         if (strlen($errormsg) && ($debugMode)) {             showErrorMessage($errormsg);             $errormsg = '';         }         if (!$showEmpty) {             return null;         }     }      $map_api_version = $config->key("google_maps", "google_map_apiversion", "2");     $module_path =     defined( 'JPATH_SITE' ) ?  'mod_sobi2gcat/' : null;      echo "\n";     echo "";     echo "\n";     echo "<div class=\"sobi2gcat{$class}\">";     ?>                    <script type="text/javascript">         window.onDomReady = DomReady;         function DomReady(func) { if(document.addEventListener) { document.addEventListener("DOMContentLoaded", func, false); } else { document.onreadystatechange = function() { readyState(func) } } }         function readyState(func) { if(document.readyState == "complete") { func(); } }     </script>                <?php     echo "\n\t ";     echo "<script src=\"{$baseAddresse}/maps?file=api&amp;v={$map_api_version}&amp;key={$config->googleMapsApiKey}\" type=\"text/javascript\"></script>";     //if ($mapControl == 3) {     //    echo "<script src=\"{$config->liveSite}/modules/{$module_path}extlargemapcontrol.js\" type=\"text/javascript\"></script>";     //}     echo "\n\t <script type=\"text/javascript\">";     echo "\n\t ";     echo "//<![CDATA[ ";     echo "\n\t\t ";     echo "function loadSobiCatOverMap() {";     echo "\n\t\t\t ";     echo "if ( GBrowserIsCompatible() ) {";     echo "\n\t\t\t\t ";               echo "\n\t    // try W3C standard approach";     echo "\n\t  var geoTimeout = 10000;";     echo "\n\t  var timeOuthandler = setTimeout(\"TryGoogleGears()\", geoTimeout);";     echo "\n\t   if(navigator.geolocation) {";     echo "\n\t    navigator.geolocation.getCurrentPosition(function(position) {";     echo "\n\t      clearTimeout(timeOuthandler);";     echo "\n\t      var latLong = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);";     echo "\n\t      document.getElementById(\"location\").innerHTML = \"Found location via W3C standard\";";     echo "\n\t      //showMap(latLong, 15);";     echo "\n\t      coordinate = latLong;";     echo "\n\t    }, function() {";     echo "\n\t      // something went wrong, try Google Gears";     echo "\n\t      clearTimeout(timeOuthandler);";     echo "\n\t      TryGoogleGears();";     echo "\n\t    }, {timeout:geoTimeout});";     echo "\n\t  }";     echo "\n\t  else";     echo "\n\t    TryGoogleGears();";                       echo "var SobiCatOverMap = new GMap2( document.getElementById(\"sobi2GcatOver\") );";     echo "\n\t\t\t\t ";     //echo "SobiCatOverMap.setCenter( new GLatLng( {$centerPointLat}, {$centerPointLong} ), {$mapsZoom} );";     echo "SobiCatOverMap.setCenter( new GLatLng( coordinate ), {$mapsZoom} );";               \\ bla bla bla........                   echo "\n\t\t\t\t ";         echo "var MarkerPoint = new GLatLng({$sobiItem->latitude},{$sobiItem->longitude});";         echo "\n\t\t\t\t ";         echo "SobiCatOverMap.addOverlay( createSobiMarker( MarkerPoint, '{$bubble}', {$itemCid} ) );";         echo "\n\t\t\t\t ";         echo "MarkerBounds.extend(MarkerPoint);";     }      if ($Automatic) {         echo "\n\t\t\t\t ";         echo "SobiCatOverMap.setCenter(MarkerBounds.getCenter());";         echo "\n\t\t\t\t ";         $incZoom = 0;         if (count($sobiItems) == 1)             $incZoom = 2;         echo "SobiCatOverMap.setZoom(SobiCatOverMap.getBoundsZoomLevel(MarkerBounds)-{$incZoom});";     }     echo "\n\t\t\t ";     echo "} ";     echo "\n\t\t ";     echo "} ";     echo "\n\t\t ";     echo "function createSobiMarker( point, html, sid ) {";     echo "\n\t\t\t ";     if( $customMarker && file_exists( _SOBI_CMSROOT.DS.$customMarker )  ) {         if( $useCatsCustomMarker ) {             echo "SCustomMarkers = new Array();";             echo $jsImgArr;             echo "\n\t\t\t ";         }         list( $mWidth, $mHeight ) = getimagesize( _SOBI_CMSROOT.DS.$customMarker );         $gxpoint = $mWidth / 2;         $gypoint = $mHeight / 2;         echo "var icon = new GIcon();";         echo "\n\t\t\t ";         echo "icon.image = \"{$config->liveSite}/{$customMarker}\";";         echo "\n\t\t\t ";         echo "icon.iconSize = new GSize( {$mWidth}, {$mHeight} );";         if( $markerShadow && file_exists( _SOBI_CMSROOT.DS.$markerShadow ) ) {             list( $msWidth, $msHeight ) = getimagesize( _SOBI_CMSROOT.DS.$markerShadow );             echo "\n\t\t\t ";             echo "icon.shadowSize = new GSize( {$msWidth}, {$msHeight} );";             echo "\n\t\t\t ";             echo "icon.shadow = \"{$config->liveSite}/{$markerShadow}\";";             echo "\n\t\t\t ";         }         echo "\n\t\t\t ";         echo "icon.iconAnchor = new GPoint( $offsetX, $offsetY );";         echo "\n\t\t\t ";         echo "icon.infoWindowAnchor = new GPoint( {$gxpoint}, 5 );";                  \\ bla bla bla....                  echo "\n\t\t\t ";         echo "var marker = new GMarker( point, icon );";     }     else {         echo "var marker = new GMarker( point );";     }     echo "\n\t\t\t";     echo "GEvent.addListener(marker, 'click', function() {";     echo "\n\t\t\t\t";     echo "marker.openInfoWindowHtml('<div class=\"sobiCatOverBubble\">'+html+'</div>');";     echo "\n\t\t\t";     echo "});";     echo "\n\t\t\t";     echo "return marker;";     echo "\n\t\t";     echo "}";     echo "\n\t\t";     echo "DomReady(loadSobiCatOverMap);";     echo "\n\t";     echo "//]]>";     echo "\n\t";     echo "</script>";     echo "\n";     echo "\n\t ";     echo "<div style=\"width: {$width}px; height:{$height}px\"  id=\"sobi2GcatOver\" ></div>";     echo "\n";     echo "</div>";     echo "\n";     echo "";     echo "\n"; } else {     return false; }  error_reporting( $restoreErrorReporting ); ?>

  2. #2
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Ciao e benvenuto.
    A) Sicuro si capisca, per uno che non conosce il problema?
    B) La pagina da un errore server.
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  3. #3
    ciao , ho tolto il link e ho messo il file php..
    dimmi cosa non si capisce che mi spiego meglio

    (ma non si puo allegare un rar o uno zip?!? )

  4. #4
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Bah...
    A) Se non si capisce, sei tu che ti sei spiegato male dovrai cercare di riprovarci come se lo dovessi spiegare ad un bambino di cinque anni, d'altronde se faccio fatica a capire il problema non saprei cosa chiederti o dirti.
    B) Dei due hai peggiorato mettendo il php:
    1) Non tutti conosco il php, e al 99% il linguaggio server per js è ininfluente.
    2) I link danno maggiori aiuti (quando funzionano)
    3) Il codice va comunque sempre postato su più righe per renderlo più leggibile


    P.S. No sul forum al massimo puoi allegare un immagine (piccola), x i file dovresti usare i servizi tipo file-host, e comunque dubito che qualcuno si scarichi uno zip lo scompatti lo "installi" per un problema altrui.
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  5. #5
    mmm.. va bè ho capito già l'andazzo del forum.
    saluti.

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.