Results 1 to 6 of 6

Thread: New Google Maps Module v1.0.0

  1. #1
    New user
    Join Date
    06-22-09.
    Location
    Germany
    Posts
    6

    Default New Google Maps Module v1.0.0

    Hello english forum,

    i know, i was absent quite a long while. The division into language forums is b*llsh*it in my opinion. Mostly you don't read the other languages - as i did. I apologize for that and try to change this situation by now

    But now to the reason of posting:

    I've released a completely redone version of my Google Maps module dlh_googlemaps. The new extension is now on API v3 and capable of many things like
    • Handle as many maps as you want.[/*:m:3i53rls2]
    • As many elements per map as needed:
      [list:3i53rls2]
    • Simple markings[/*:m:3i53rls2]
    • Complex markings with icon and shadow[/*:m:3i53rls2]
    • Infowindows[/*:m:3i53rls2]
    • Ground overlays[/*:m:3i53rls2]
    • (Poly)lines[/*:m:3i53rls2]
    • Polygones[/*:m:3i53rls2]
    • Circles[/*:m:3i53rls2]
    • Rectangles[/*:m:3i53rls2]
    [/*:m:3i53rls2][*]Linking of the Google Maps route planner from the infowindow of a marker[/*:m:3i53rls2][*]Direct linking of pages and urls from markers[/*:m:3i53rls2][*]Geo-coding of addresses[/*:m:3i53rls2][*]Module for use in Contao layouts[/*:m:3i53rls2][*]Content element for use in articles[/*:m:3i53rls2][*]Content element for use as a static map (png)[/*:m:3i53rls2][*]Dynamic markings and modifications while running[/*:m:3i53rls2][*]No more use of the Google Maps API Key by use of the Google Maps API V3[/*:m:3i53rls2][/list:u:3i53rls2]

    Migration is a bit tricky. Mostly normal maps are transferred into the new module structure, but sometimes it fails. Maps that use multiple elements (by those JS-blocks) can't be converted completly - only the map is, but the markers aren't.

    Please note that migration is only possible from 0.1.5 and Contao 2.9, nothig before that. So please update your system before updateing the extension. Because of the use of the runonce.php within the migration it's better to update the module alone, not together with other applications.

    I'm looking for translaters in other languages. It would be even fine, if a native english speaker would have a look at my english translation.

    But now have fun and i promise too keep an eye more on your bug statements than the months before

    Greetings,

    Christian
    "Read the source, Luke"

  2. #2
    User
    Join Date
    06-20-09.
    Location
    Middlesbrough, UK
    Posts
    246

    Default Re: New Google Maps Module v1.0.0

    Hi Christian,

    I have had a play with new version and it is amazing!

    I have had some mixed results with upgrades but it didn't take me long to sort them out. There are some new very powerful features.

    I was testing the polygon feature. I assume this is to map a route like a bike route or walk etc. I didn't add any lines but tried to click on the icon next to the title for adding new areas for extra points and it didn't launch anything. Is this icon for finding geo coordinates? This would be great if you could find geo coordinates without having to go off to another site.

    Great module, hope you and others from the German forum can spend more time in the English forum too.
    360fusion: Virtual Tours - Web Design
    Social Media: Twitter - Facebook Page

  3. #3
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: New Google Maps Module v1.0.0

    Hi Christian,
    I've just been playing with your module and it is Fantastic.

    A question: In the latest (v1.0.0) I cannot get more than one marker per map to show, even if I have 2 marker elements published. Is this intentional, a bug or I'm missing something?

    A bug maybe: If I type in a wrongly formatted or false address into the Address For Geocoding field, the Geo-coordinates field will show "No geocoding possible."
    Now if I correct this address - or type in a different valid one - and save, I still get "No geocoding possible."
    I need to manually clear the "No geocoding possible." from the Geo-coordinates field before it will get the co-ordinates of the new address.

    Also, if I type in a different address and save whilst the Geo-coordinates field has a correct value - the co-ordinates remain for the old address. So I end up with an address with wrong co-ordinates.

    I know this is explained
    In case of the field ´geo-coordinates´ being empty, on saving the record the geo-coodinates of this address are generated automatically
    but it is unintuitive, and can lead you to think you've saved something when you haven't.

    I would suggest the following as a solution
    - to throw an error and exception on noCurl and noCoords, instead of storing them in the Geo-coordinates field "center".
    -make the Geo-coordinates field read-only, so it can be seen but not altered
    -change the logic of the generateCoords() callback, so an address OR co-ordinates can be entered in the "Address For Geocoding" geocoderAddress field with a pregmatch routine

    Latitude and longitude coordinate strings are defined using numerals within a comma-separated text string. For example, "40.714728,-73.998672" is a valid locations value. Latitude and longitude values must correspond to a valid location on the face of the earth. Latitudes can take any value between -90 and 90 while longitude values can take any value between -180 and 180. If you specify an invalid latitude or longitude value, your request will be rejected as a bad request.
    -to place input that passes valididation as a lat/long pair directly into "center" without running curl, and run curl on non-validated input.


    Also, to have Earth show as a button on the map would be great (hybrid, satellite, terrain, map, earth).

    I'll have a look at altering your code to see if I can affect these changes and report back.

    Thanks Christian for a great utility.

  4. #4
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: New Google Maps Module v1.0.0

    Ok... I see Google Earth is out as the V3 API doesn't support it, so cancel that one.

    And multiple markers works fine .... it was just that my co-ordinates numbers too close together, so the 2 markers actually refered to the same location ops:

    I think it would be good if the markers also accepted an address, like the map does.

  5. #5
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: New Google Maps Module v1.0.0

    I changed 2 dca/tl_dlh_googlemaps fields (so the save_callback to generateCoords() is now on "geocoderAddress", and "center" is now readonly to prevent user input and only show verified co-ordinates.

    Code:
    		'center' => array
    		(
    			'label'                   => &$GLOBALS['TL_LANG']['tl_dlh_googlemaps']['center'],
    			'exclude'                 => true,
    			'search'                  => true,
    			'inputType'               => 'text',
    			'eval'                    => array('maxlength'=>64, 'readonly'=>'readonly')
    		),
    		'geocoderAddress' => array
    		(
    			'label'                   => &$GLOBALS['TL_LANG']['tl_dlh_googlemaps']['geocoderAddress'],
    			'exclude'                 => true,
    			'search'                  => true,
    			'inputType'               => 'text',
    			'eval'                    => array('maxlength'=>255, 'tl_class'=>'long clr'),
    			'save_callback' => array
    			(
    				array('tl_dlh_googlemaps', 'generateCoords')
    			)			
    		),
    and i changed generateCoords() to accept addresses or co-ordinates via the geocoderAddress field
    In the case of no input, it centers a map on 0,0 (before any wrong maps wouldn't instantiate, now they will show as blue, because 0,0 is in the sea.


    Code:
    	function generateCoords($varValue, DataContainer $dc) 
    	{
    		   
    			if ($varValue) //if there is input in the address field then run validation on geocoderAddress field to see if it is a valid lat/long pair separated by a comma	
    			{
    			$myArray = explode(',', $varValue); //split string on FIRST comma
    
    					if(count($myArray) == 2) //there are two parts... so test furthur
    					{
    							//is first part (as number)  between -90 and 90  AND is second part (as number)  between -180 and 180
    							if(((int)$myArray[0] > -90 && (int)$myArray[0] < 90)  && (((int)$myArray[1] > -180 && (int)$myArray[1] < 180)))
    							{
    							//it validates as latlong -  place it in "center"
    							$this->Database->prepare("UPDATE tl_dlh_googlemaps SET center=? WHERE id=?")
    							->limit(1)
    							->execute($varValue,$dc->id);
    							
    							}
    
    					}else //not valid input as lat/long - run curl
    					{
    					$strGeoURL = 'http://maps.google.com/maps/api/geocode/xml?address='.str_replace(' ', '+', $varValue).'&sensor=false'.($dc->activeRecord->geocoderCountry ? '&region='.$dc->activeRecord->geocoderCountry : '');
    					
    							if(function_exists("curl_init"))
    							{
    							$curl = curl_init();
    					
    									if($curl)
    									{
    					
    											if(curl_setopt($curl, CURLOPT_URL, $strGeoURL) && curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1) && curl_setopt($curl, CURLOPT_HEADER, 0))
    											{
    											$curlVal = curl_exec($curl);
    											curl_close($curl);
    											$xml = new SimpleXMLElement($curlVal);
    											
    													if($xml->result->geometry->location->lat != '' && $xml->result->geometry->location->lng != '') //ok curl return verified
    													{
    													$returnedLatLong = $xml->result->geometry->location->lat . ',' . $xml->result->geometry->location->lng;
    													//place in center field
    													$this->Database->prepare("UPDATE tl_dlh_googlemaps SET center=? WHERE id=?")
    													->limit(1)
    													->execute($returnedLatLong,$dc->id);
    													
    													}else
    													{
    													//throw exception and error at top of page  No Co-ordinates returned
    													$GLOBALS['TL_LANG']['ERR']['general'] = $GLOBALS['TL_LANG']['tl_dlh_googlemaps']['references']['noCoords'];
    													throw new Exception(sprintf($GLOBALS['TL_LANG']['tl_dlh_googlemaps']['references']['noCoords'], $varValue));
    													}
    											
    											}
    						
    									}else
    									{
    									//throw exception and error at top of page No Curl
    									$GLOBALS['TL_LANG']['ERR']['general'] = $GLOBALS['TL_LANG']['tl_dlh_googlemaps']['references']['noCurl'];
    									throw new Exception(sprintf($GLOBALS['TL_LANG']['tl_dlh_googlemaps']['references']['noCurl'], $varValue));
    									}
    									
    							}					
    					
    					}
    					
    			return $varValue;					
    			
    			}else
    			{
    			//there is no input in the address field  ... Center on 0,0 
    			$this->Database->prepare("UPDATE tl_dlh_googlemaps SET center=? WHERE id=?")
    			->limit(1)
    			->execute('0,0',$dc->id);
    
    			return $varValue;			
    			}
    			
    
    
    	}
    Dunno what you think Christian, but these changes work well for me.
    Of course the language files would need to change to reflect the fact theres now only one input field.
    In English for example:
    Code:
    $GLOBALS['TL_LANG']['tl_dlh_googlemaps']['center'] = array('Verified Geo-coordinates', 'The verified geo-coordinates of the map center. READONLY.');
    $GLOBALS['TL_LANG']['tl_dlh_googlemaps']['geocoderAddress'] = array('Address or Geo-coordinates', 'Enter an address or geo-coordinates (e.g. 48.856846,2.351024) to center the map on.');
    I think the same system of a readonly verified field and a address/lat-long input field- at least on the markers and infowindows - would be good, as nobody really knows the lat/long of several houses in a suburb for instance, and it would be much easier to enter them as addresses than as lat/long.
    I do like however the fact the markers give you the default map lat/long point initially.

    anyway, just a suggestion,
    cheers, murray.

  6. #6
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: New Google Maps Module v1.0.0

    I've changed the above a bit -
    Code:
    	function generateCoords($varValue, DataContainer $dc) 
    	{
    	
    			//if there is input in the address field then run validation on singleCoords field to see if it is a valid lat/long pair separated by a comma		   
    			if ($varValue || $varValue == 0)
    			{
    			
    			//split string on FIRST comma
    			$myArray = explode(',', $varValue);
    			
    					if(count($myArray) == 2)
    					{
    					//there are two parts... convert parts to integers and test furthur
    					(int)$part1 = $myArray[0];
    					(int)$part2 = $myArray[1];
    					
    							//is first part (as number)  between -90 and 90  AND is second part (as number)  between -180 and 180  
    							//regex: does each part contain EITHER an optional minus sign, 1 or more digits, an optional dot followed by one or more digits OR is each part an optional minus sign and one or more digits only
    							if(preg_match("/^-?([0-9]+\.[0-9]+|[0-9]+)$/",$part1) && $part1 > -90 && $part1 < 90 && preg_match("/^-?([0-9]+\.[0-9]+|[0-9]+)$/",$part2) && $part2 > -180 &&  $part2 < 180)
    							{
    							
    							//it validates as latlong -  place it in "center"
    							$this->Database->prepare("UPDATE tl_dlh_googlemaps SET center=? WHERE id=?")
    							->limit(1)
    							->execute($varValue,$dc->id);
    							
    							return $varValue;
    							}
    
    					}
    					
    			//Validation failed, so pass to geocoder			
    
    			$strGeoURL = 'http://maps.google.com/maps/api/geocode/xml?address='.str_replace(' ', '+', $varValue).'&sensor=' . ($dc->activeRecord->sensor ? 'true' : 'false') . ($dc->activeRecord->geocoderCountry ? '&region='.$dc->activeRecord->geocoderCountry : '');
    			
    			
    					if(function_exists("curl_init"))
    					{
    					$curl = curl_init();
    					
    							if($curl)
    							{
    					
    									if(curl_setopt($curl, CURLOPT_URL, $strGeoURL) && curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1) && curl_setopt($curl, CURLOPT_HEADER, 0))
    									{
    									$curlVal = curl_exec($curl);
    									curl_close($curl);
    									$xml = new SimpleXMLElement($curlVal);
    											
    											if($xml->result->geometry->location->lat != '' && $xml->result->geometry->location->lng != '')
    											{
    											//it validates as latlong -  return
    											$valid = $xml->result->geometry->location->lat . ',' . $xml->result->geometry->location->lng;
    											
    											//place in center field
    											$this->Database->prepare("UPDATE tl_dlh_googlemaps SET center=? WHERE id=?")
    											->limit(1)
    											->execute($valid,$dc->id);
    											
    											return $varValue;
    											
    											}else
    											{
    											//throw exception and error at top of page  No Co-ordinates returned
    											$GLOBALS['TL_LANG']['ERR']['general'] = $GLOBALS['TL_LANG']['tl_dlh_googlemaps']['references']['noCoords'];
    											throw new Exception(sprintf($GLOBALS['TL_LANG']['tl_dlh_googlemaps']['references']['noCoords'], $varValue));
    											
    											}
    											
    									}
    						
    							}
    									
    					}else
    					{
    					//throw exception and error at top of page No Curl
    					$GLOBALS['TL_LANG']['ERR']['general'] = $GLOBALS['TL_LANG']['tl_dlh_googlemaps']['references']['noCurl'];
    					throw new Exception(sprintf($GLOBALS['TL_LANG']['tl_dlh_googlemaps']['references']['noCurl'], $varValue));
    					}
    
    				
    			//throw exception and error at top of page  No Co-ordinates returned
    			$GLOBALS['TL_LANG']['ERR']['general'] = $GLOBALS['TL_LANG']['tl_dlh_googlemaps']['references']['noCoords'];
    			throw new Exception(sprintf($GLOBALS['TL_LANG']['tl_dlh_googlemaps']['references']['noCoords'], $varValue));
    				
    			
    			}else
    			{
    			
    			//there is no input in the address field  ... return and mandatory error will be thrown
    			return $varValue;				
    			}					
    
    	}
    the previous validation was letting a couple of things through - as well I've done the same to the markers and infowindows so they accept and geocode addresses.

    Also there is a small fault with the default marker latlong, which I've fixed -it was drawing the "center" from other parents.
    Just pm me Christian if you want to check out what I've done
    Theres no change to the database, 2 fields have minor changes (readonly and mandatory values), theres 2 save_callbacks added, and updatePalette() has been altered as below

    //this was wrong, it was setting new marker default to the centre of a completely different map ....the last one in the list
    Code:
    			if ($objMap->numRows > 0)
    			{
    
    					if (!$objElement->singleCoords)
    					{
    					$this->Database->prepare("UPDATE tl_dlh_googlemaps_elements SET singleCoords =? WHERE id=?")
    					->limit(1)
    					->execute($objMap->center,$dc->id);
    					}
    					
    			}
    Again, its a great extension,
    cheers, murray

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •