Zum Inhalt springen

Googlemaps in eigener Extension

Erstellt am 8. März 2007 · 7 Antworten · letzte Antwort am 13. März 2007

Tags: Frage

azimmer ·

Hallo Forum,
ich habe mir mal eine eigene kleine Extension geschrieben um Googlemapdaten anzuzeigen. Das klappt auch wunderbar im Firefox. Nur der IE macht Probleme.

Anzusehen unter:http://www.das-blau.de/index.php?id=86

Das ist die Klasse:
--------------------------------------------

<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2007  <>
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

require_once(PATH_tslib.'class.tslib_pibase.php');



/**
 * Plugin 'Weinregion' for the 'weingutmap' extension.
 *
 * @author	 <>
 * @package	TYPO3
 * @subpackage	tx_weingutmap
 */
class tx_weingutmap_pi1 extends tslib_pibase {
	var $prefixId      = 'tx_weingutmap_pi1';		// Same as class name
	var $scriptRelPath = 'pi1/class.tx_weingutmap_pi1.php';	// Path to this script relative to the extension dir.
	var $extKey        = 'weingutmap';	// The extension key.
	
	/**
	 * The main method of the PlugIn
	 *
	 * @param	string		$content: The PlugIn content
	 * @param	array		$conf: The PlugIn configuration
	 * @return	The content that is displayed on the website
	 */
	function main($content,$conf)	{
		$this->conf=$conf;
		$this->pi_setPiVarDefaults();
		$this->pi_loadLL();
		$this->pi_USER_INT_obj=1;	// Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object!
	
    $query = "SELECT tx_weingutmap_title,tx_weingutmap_latitude,tx_weingutmap_longitude,tx_weingutmap_zoom " .
                "FROM tt_content " .
              "WHERE uid=".$this->cObj->data['uid'];
    $res = mysql(TYPO3_db,$query);        
    $row = mysql_fetch_array($res);

	$GLOBALS['TSFE']->additionalHeaderData['user_unterkunftsverwaltung'] ='<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAsG8bXf-BPScjizPWAzUt7RSL2PDHjd9-hp44infeAfToqRQDZRQC3xe7BeEBthrKqccdLrizy6JMAA" type="text/javascript"></script>

		<style type="text/css">
    v\:* {
      behavior:url(#default#VML);
    }
    </style>
	';



    $content="
      <div id='map' style='width: 500px; height: 400px'></div>

      <script type='text/javascript'>
        //<![CDATA[

        if (GBrowserIsCompatible()) {
          var map = new GMap2(document.getElementById('map'));
          map.addControl(new GLargeMapControl());
          map.addControl(new GMapTypeControl());
          map.setCenter(new GLatLng(".$row['tx_weingutmap_latitude'].", ".$row['tx_weingutmap_longitude']."), ".$row['tx_weingutmap_zoom'].", G_HYBRID_MAP);
        }
        //]]>
      </script>
    ";

	
		return $this->pi_wrapInBaseClass($content);
	}
}



if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/weingutmap/pi1/class.tx_weingutmap_pi1.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/weingutmap/pi1/class.tx_weingutmap_pi1.php']);
}

?>

Kann mir da mal jemand bitte helfen?

viele Grüße
Armin

just2b ·

Hallo Armin,

bitte die Codeboxen verwenden, ich hab das dieses mal für dich gemacht.
Hmm seh keine größeren Fehler, außer dass du die API für Abfragen nehmen solltest, aber ok.

schmeiss doch mal alles raus was du nicht unbedingt brauchst, sprich
- css 62-66
- die abfrage und ersetz die werte statisch

lg georg

azimmer ·

Hallo Georg,
danke für die schnelle Antwort.

Das mit den Codeboxen weiss ich nicht wie das geht.

zur Extension:
Ich habe das Beispiel aus einem Typo3 Lernvideo. Den Dozenten habe ich schon kontaktiert - aber leider noch keine Antwort bekommen.

Das Css war ursprünglich nicht drin. Ist von hier:
http://philipp.gothic-singles.de/demo.php

Ich habe schon eine Beschreibung des Fehlers gefunden:
http://vidmar.net/weblog/archive/2005/08/22/2121.aspx

Aber ich bekomme es ums verrecken nicht hin. Sobald ich das ganze in einer T3-Extension umsetze. Irgendwo mache ich nen ganz doofen Fehler.

Ich brauche das ganze um es in meiner eigenen Extension zu verwenden. Die soll Ferienhäuser anzeigen und als Firmenverzeichnis dienen.

Vielleicht kannst Du mir noch einen Tipp geben. Ich drehe sonst noch ganz durch.
#angry#

viele Grüße
Armin

azimmer ·

Hallo,
Hier nochmal der Link zu meinem Testbeispiel. Oben der funktioniert nicht mehr.

http://www.ferienziel-natur.de/index.php?id=103

<body onunload="GUnload()">

habe ich von hier.
http://www.google.com/apis/maps/documentation/

Wenn ich richtig verstehe, was ich bisher zu dem Fehler gelesen habe, liegt es daran, dass im Seitenquelltext Javascriptcode im body oder headbereich an der falschen Stelle erzeugt wird (von Typo3?). Aber was kann ich dagegen tun?
Oder bin ich auf der total falschen Spur?

Ich habe das ganze nochmal neu gemacht. Jetzt sieht es so aus. Funktioniert aber auch nicht.

require_once(PATH_tslib.'class.tslib_pibase.php');


class tx_testgooglemap_pi1 extends tslib_pibase {
	var $prefixId = 'tx_testgooglemap_pi1';		// Same as class name
	var $scriptRelPath = 'pi1/class.tx_testgooglemap_pi1.php';	// Path to this script relative to the extension dir.
	var $extKey = 'testgooglemap';	// The extension key.
	

	function main($content,$conf)	{
		$this->conf=$conf;
		$this->pi_setPiVarDefaults();
		$this->pi_loadLL();
		$this->pi_USER_INT_obj=1;	// Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object!

		$GLOBALS['TSFE']->additionalHeaderData['user_unterkunftsverwaltung'] = '<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAsG8bXf-BPScjizPWAzUt7RRJufgowM7Ob5smfJQElb4jfhF1fBQxgvrQhOkrFuCjW_3TutRl7C5fVw" type="text/javascript"></script>';
	
	$content= "<div id='map' style='width: 460px; height: 400px'></div>
                        <script type='text/javascript'>
                          //<![CDATA[
                          var map = new GMap2(document.getElementById('map'));
                          map.addControl(new GSmallMapControl());
                          map.addControl(new GMapTypeControl());
                          map.setCenter(new GLatLng(52.48142115832729,13.426837921142578-), 13, G_HYBRID_MAP);
                          //]]>
                       </script>
									    ";
	
		return $this->pi_wrapInBaseClass($content);
	}
}



if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/testgooglemap/pi1/class.tx_testgooglemap_pi1.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/testgooglemap/pi1/class.tx_testgooglemap_pi1.php']);
}

?>

Grüße
Armin

just2b ·

Nur mal ein weiteres Bsp:

eine js datei mit sowas drin

function loadPoint() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("mapLoad"));
    

    var center = new GLatLng(43, 13);
    map.setCenter(center, 3);
    geocoder = new GClientGeocoder();
    
    map.addControl(new GSmallMapControl());
    //map.addControl(new GOverviewMapControl());
    
    var marker = new GMarker(center, {draggable: true});
    map.enableDragging();
    map.addOverlay(marker);
    

  }
}

,

dann noch in deinem php

<?
        $GLOBALS['TSFE']->additionalHeaderData['b121211'] = '<script src="http://maps.google.com/maps?file=api&amp;v=2.61&amp;key='.$this->confArr['googleKey'].'" type="text/javascript"></script>'; 
    $GLOBALS['TSFE']->additionalHeaderData['b121212'] = '<script type="text/javascript" src="pfad_zur_js-datei.js"></script>';

$content = '<div id="mapLoad" style="width:100px;height:100px"></div>

und in deinen body-Tag ein onload="loadPoint()"

georg

azimmer ·

Hallo Georg,
erst einmal ein ganz großes Dankeschön an Dich für Deine Unterstützung. Ich bin dadurch einen riesen Schritt weiter.

Kurz nochmal mein Script:

<?
class tx_testgooglemap_pi1 extends tslib_pibase {
	var $prefixId = 'tx_testgooglemap_pi1';		// Same as class name
	var $scriptRelPath = 'pi1/class.tx_testgooglemap_pi1.php';	// Path to this script relative to the extension dir.
	var $extKey = 'testgooglemap';	// The extension key.
	
	/**
	 * The main method of the PlugIn
	 *
	 * @param	string		$content: The PlugIn content
	 * @param	array		$conf: The PlugIn configuration
	 * @return	The content that is displayed on the website
	 */
	function main($content,$conf)	{
		$this->conf=$conf;
		$this->pi_setPiVarDefaults();
		$this->pi_loadLL();
		$this->pi_USER_INT_obj=1;	// Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object!



		//Code aus typo3.net Forum
	        $GLOBALS['TSFE']->additionalHeaderData['b121211'] = '<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAsG8bXf-BPScjizPWAzUt7RRJufgowM7Ob5smfJQElb4jfhF1fBQxgvrQhOkrFuCjW_3TutRl7C5fVw" type="text/javascript"></script>';
    		//$GLOBALS['TSFE']->additionalHeaderData['b121212'] = '<script type="text/javascript" src="typo3conf/ext/testgooglemap/pi1/testgooglemap.js"></script>';

		// Beispiel rg_googlemap_original
		$GLOBALS["TSFE"]->additionalJavaScript['user_unterkunftsverwaltung'] = $this->getjs();
		
		$content = '<div id="map" style="width:400px;height:400px"></div>'; 
	
		return $this->pi_wrapInBaseClass($content);
	}// Ende Main()

  function getjs() {

	//DB-Abfrage  - Testdatenbank - 
	$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('latitude, longitude, zoom', 'user_unterkunftsverwaltung_main', "deleted = 0 AND hidden = 0 AND uid = 1" , '','');
	$row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);


	// sichern funktioniert
   $temp ="function loadpoint() {
           if (GBrowserIsCompatible()) {
	          var map = new GMap2(document.getElementById('map'));
	          map.addControl(new GLargeMapControl());
	          map.addControl(new GMapTypeControl());
          	  map.setCenter(new GLatLng(".$row['latitude'].", ".$row['longitude']."), ".$row['zoom'].", G_HYBRID_MAP);	          		
        	}
        }	
        ";
        
        
	return $temp;

      }//ende getjs()


} //Ende Klasse


if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/testgooglemap/pi1/class.tx_testgooglemap_pi1.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/testgooglemap/pi1/class.tx_testgooglemap_pi1.php']);
}

?>

Link zur Beispielseite:
http://www.ferienziel-natur.de/regionen/saarland/radtouren.html

Es läuft jetzt auch im IE.

Aber ein Problem habe ich noch. Wie kann ich das ganze aufrufen ohne was im "<body>" zu ändern? Sorry ich hab wenig bis keine Ahnung von Javascript.

viele Grüße
Armin

just2b ·

wenn du noch kein bodyonload hast, dann kannst du im js auch sowas schreiben:

window.onload = makeMap;

wenn makeMap() deine js-Funktion ist

lg georg