Index: /extensions/rv_gmaps/trunk/admin/admin_config.php
===================================================================
--- /extensions/rv_gmaps/trunk/admin/admin_config.php	(revision 12700)
+++ /extensions/rv_gmaps/trunk/admin/admin_config.php	(revision 12701)
@@ -1,4 +1,4 @@
 <?php 
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
 
 include_once( dirname(__FILE__).'/../include/functions_map.php' );
Index: /extensions/rv_gmaps/trunk/admin/admin_sync.php
===================================================================
--- /extensions/rv_gmaps/trunk/admin/admin_sync.php	(revision 12700)
+++ /extensions/rv_gmaps/trunk/admin/admin_sync.php	(revision 12701)
@@ -1,19 +1,4 @@
 <?php
 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
-
-function parse_fract( $f )
-{
-  $nd = explode( '/', $f );
-  return $nd[0]/$nd[1];
-}
-
-function parse_lat_lon( $arr )
-{
-  $v=0;
-  $v += parse_fract( $arr[0] );
-  $v += parse_fract( $arr[1] )/60;
-  $v += parse_fract( $arr[2] )/3600;
-  return $v;
-}
 
 if ( isset($_POST['submit']) )
@@ -36,5 +21,5 @@
 {
 	include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
-
+  include_once( dirname(__FILE__).'/../include/functions_metadata.php' );
   $where_clauses = array();
   if ( $sync_options['cat_id']!=0 )
@@ -73,32 +58,16 @@
 		if ( empty($exif) )
 			continue;
-		$exif = array_intersect_key( $exif, array_flip( array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude') ) );
-		if ( count($exif)!=4 )
-			continue;
-		if ( !in_array($exif['GPSLatitudeRef'], array('S', 'N') ) )
+		$ll = exif_to_lat_lon($exif);
+		if (!is_array($ll))
 		{
-			$errors[] = $filename. ': GPSLatitudeRef not S or N';
+			if (!empty($ll))
+				$errors[] = $filename. ': '.$ll;
 			continue;
 		}
-		if ( !in_array($exif['GPSLongitudeRef'], array('W', 'E') ) )
-		{
-			$errors[] = $filename. ': GPSLongitudeRef not W or E';
-			continue;
-		}
-		if (!is_array($exif['GPSLatitude']) or !is_array($exif['GPSLongitude']) )
-		{
-			$errors[] = $filename. ': GPSLatitude and GPSLongitude are not arrays';
-			continue;
-		}
-		$lat = parse_lat_lon( $exif['GPSLatitude'] );
-		if ( $exif['GPSLatitudeRef']=='S' )
-			$lat = -$lat;
-		$lon = parse_lat_lon( $exif['GPSLongitude'] );
-		if ( $exif['GPSLongitudeRef']=='W' )
-			$lon = -$lon;
+
 		$datas[] = array (
 			'id' => $image['id'],
-			'lat' => $lat,
-			'lon' => $lon,
+			'lat' => $ll[0],
+			'lon' => $ll[1],
 			);
   }
Index: /extensions/rv_gmaps/trunk/include/functions_metadata.php
===================================================================
--- /extensions/rv_gmaps/trunk/include/functions_metadata.php	(revision 12701)
+++ /extensions/rv_gmaps/trunk/include/functions_metadata.php	(revision 12701)
@@ -0,0 +1,38 @@
+<?php
+function parse_fract( $f )
+{
+	$nd = explode( '/', $f );
+	return $nd[0]/$nd[1];
+}
+
+function parse_lat_lon( $arr )
+{
+	$v=0;
+	$v += parse_fract( $arr[0] );
+	$v += parse_fract( $arr[1] )/60;
+	$v += parse_fract( $arr[2] )/3600;
+	return $v;
+}
+
+function exif_to_lat_lon( $exif )
+{
+	$exif = array_intersect_key( $exif, array_flip( array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude') ) );
+	if ( count($exif)!=4 )
+		return '';
+	if ( !in_array($exif['GPSLatitudeRef'], array('S', 'N') ) )
+		return 'GPSLatitudeRef not S or N';
+	if ( !in_array($exif['GPSLongitudeRef'], array('W', 'E') ) )
+		return 'GPSLongitudeRef not W or E';
+	if (!is_array($exif['GPSLatitude']) or !is_array($exif['GPSLongitude']) )
+		return 'GPSLatitude and GPSLongitude are not arrays';
+		
+	$lat = parse_lat_lon( $exif['GPSLatitude'] );
+	if ( $exif['GPSLatitudeRef']=='S' )
+		$lat = -$lat;
+	$lon = parse_lat_lon( $exif['GPSLongitude'] );
+	if ( $exif['GPSLongitudeRef']=='W' )
+		$lon = -$lon;
+	return array ($lat,$lon);
+}
+
+?>
Index: /extensions/rv_gmaps/trunk/main.inc.php
===================================================================
--- /extensions/rv_gmaps/trunk/main.inc.php	(revision 12700)
+++ /extensions/rv_gmaps/trunk/main.inc.php	(revision 12701)
@@ -1,5 +1,5 @@
 <?php /*
 Plugin Name: RV Maps&Earth
-Version: 2.3.a
+Version: 2.3.b-alpha
 Description: Extend your gallery with Google Maps and Google Earth ...
 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=122
@@ -7,6 +7,6 @@
 Author URI: http://www.modusoptimus.com/
 */
-define( 'RVM_PLUGIN_VERSION', '2.3.a');
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+define( 'RVM_PLUGIN_VERSION', '2.3.b-alpha');
+defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
 
 add_event_handler('loc_end_index', 'rvm_end_index' );
@@ -20,4 +20,11 @@
 $rvm_dir = basename( dirname(__FILE__) );
 
+global $conf;
+if (@$conf['gmaps_auto_sync'])
+{
+  $conf['use_exif_mapping']['lat'] = 'lat';
+  $conf['use_exif_mapping']['lon'] = 'lon';
+  add_event_handler('format_exif_data', 'rvm_format_exif', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
+}
 
 function rvm_index_cat_thumbs_displayed()
@@ -132,3 +139,17 @@
 }
 
+function rvm_format_exif($exif, $file, $map)
+{
+  if (isset($map['lat']))
+  {
+		include_once( dirname(__FILE__) .'/include/functions_metadata.php');
+		$ll = exif_to_lat_lon($exif);
+		if (is_array($ll))
+		{
+			$exif[$map['lat']] = $ll[0];
+			$exif[$map['lon']] = $ll[1];
+		}
+  }
+  return $exif;
+}
 ?>
Index: /extensions/rv_gmaps/trunk/maintain.inc.php
===================================================================
--- /extensions/rv_gmaps/trunk/maintain.inc.php	(revision 12700)
+++ /extensions/rv_gmaps/trunk/maintain.inc.php	(revision 12701)
@@ -66,5 +66,5 @@
 
   $q = '
-DELETE FROM '.CONFIG_TABLE.' WHERE param="gmaps_api_key" LIMIT 1';
+DELETE FROM '.CONFIG_TABLE.' WHERE param IN("gmaps_api_key","gmaps_auto_sync")';
   pwg_query( $q );
   
Index: /extensions/rv_gmaps/trunk/template/data_handler.js
===================================================================
--- /extensions/rv_gmaps/trunk/template/data_handler.js	(revision 12700)
+++ /extensions/rv_gmaps/trunk/template/data_handler.js	(revision 12701)
@@ -12,5 +12,5 @@
 
 	google.maps.event.bind( this._map, "click", this, this._onMapClick);
-	google.maps.event.bind( this._infoWindow, "domready", this, this._onInfoWindowDomReady);
+	//google.maps.event.bind( this._infoWindow, "domready", this, this._onInfoWindowDomReady);
 }
 
@@ -161,4 +161,5 @@
 		google.maps.event.removeListener(h);
 
+	google.maps.event.addListenerOnce( this._infoWindow, "domready", pwgBind(this, this._onInfoWindowDomReady) );
 	this._infoWindow.setContent( content );
 	this._infoWindow.setPosition( marker.getPosition() );
Index: /extensions/rv_gmaps/trunk/template/data_loader.js
===================================================================
--- /extensions/rv_gmaps/trunk/template/data_loader.js	(revision 12700)
+++ /extensions/rv_gmaps/trunk/template/data_loader.js	(revision 12701)
@@ -5,5 +5,5 @@
 		{
 			reload_data_timeout: 200,
-			rectangle_of_confusion: new google.maps.Size(32,16)
+			rectangle_of_confusion: new google.maps.Size(16,32)
 		}
 		, opts || {} );
@@ -75,6 +75,25 @@
 _loadData: function()
 {
-	var bounds = this._map.getBounds();
-
+	var bounds = new google.maps.LatLngBounds( this._map.getBounds().getSouthWest(), this._map.getBounds().getNorthEast() );
+	
+	//bug as of v 3.7 - 
+	var isOver = false;
+	if (bounds.getSouthWest().lng() < bounds.getNorthEast().lng())
+	{
+		if ( this._map.getCenter().lng()<bounds.getSouthWest().lng() || this._map.getCenter().lng()>bounds.getNorthEast().lng() )
+		{
+			isOver = true;
+		}
+	}
+	else if ( this._map.getCenter().lng()>bounds.getNorthEast().lng() && this._map.getCenter().lng()<bounds.getSouthWest().lng() )
+	{
+		isOver = true;
+	}
+	
+	if (isOver)
+		bounds = new google.maps.LatLngBounds( new google.maps.LatLng(this._map.getBounds().getSouthWest().lat(),-179.9), new google.maps.LatLng(this._map.getBounds().getNorthEast().lat(), 179.9) );
+	//end bug
+	
+	
 	var latRange = bounds.toSpan().lat();
 	var latPrec = latRange * this.options.rectangle_of_confusion.height / this._map.getDiv().offsetHeight;
Index: /extensions/rv_gmaps/trunk/template/map.tpl
===================================================================
--- /extensions/rv_gmaps/trunk/template/map.tpl	(revision 12700)
+++ /extensions/rv_gmaps/trunk/template/map.tpl	(revision 12701)
@@ -51,5 +51,5 @@
 	if (console)
 	{
-		console.debug(msg + " b="+map.getBounds().toUrlValue() + " c="+map.getCenter().toUrlValue() + " z="+map.getZoom() );
+		console.log(msg + " b="+map.getBounds().toUrlValue() + " c="+map.getCenter().toUrlValue() + " z="+map.getZoom() );
 	}
 }
@@ -163,5 +163,5 @@
 		if (lang_str == undefined)
 		{
-			if (document.is_debug) google.maps.Log.write("Language string undefined '"+ str+"'");
+			if (document.is_debug) glog("Language string undefined '"+ str+"'");
 			return str;
 		}
Index: tensions/rv_gmaps/trunk/template/markers/small_dot_blue.tpl
===================================================================
--- /extensions/rv_gmaps/trunk/template/markers/small_dot_blue.tpl	(revision 12700)
+++ 	(revision )
@@ -1,8 +1,0 @@
-var icon = new google.maps.Icon();
-icon.image = "http://labs.google.com/ridefinder/images/mm_20_blue.png";
-icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
-icon.iconSize = new google.maps.Size(12, 20);
-icon.shadowSize = new google.maps.Size(22, 20);
-icon.iconAnchor = new google.maps.Point(6, 20);
-icon.infoWindowAnchor = new google.maps.Point(5, 1);
-return icon;
Index: tensions/rv_gmaps/trunk/template/markers/small_dot_green.tpl
===================================================================
--- /extensions/rv_gmaps/trunk/template/markers/small_dot_green.tpl	(revision 12700)
+++ 	(revision )
@@ -1,8 +1,0 @@
-var icon = new google.maps.Icon();
-icon.image = "http://labs.google.com/ridefinder/images/mm_20_green.png";
-icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
-icon.iconSize = new google.maps.Size(12, 20);
-icon.shadowSize = new google.maps.Size(22, 20);
-icon.iconAnchor = new google.maps.Point(6, 20);
-icon.infoWindowAnchor = new google.maps.Point(5, 1);
-return icon;
Index: tensions/rv_gmaps/trunk/template/markers/small_dot_purple.tpl
===================================================================
--- /extensions/rv_gmaps/trunk/template/markers/small_dot_purple.tpl	(revision 12700)
+++ 	(revision )
@@ -1,8 +1,0 @@
-var icon = new google.maps.Icon();
-icon.image = "http://labs.google.com/ridefinder/images/mm_20_purple.png";
-icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
-icon.iconSize = new google.maps.Size(12, 20);
-icon.shadowSize = new google.maps.Size(22, 20);
-icon.iconAnchor = new google.maps.Point(6, 20);
-icon.infoWindowAnchor = new google.maps.Point(5, 1);
-return icon;
Index: tensions/rv_gmaps/trunk/template/markers/small_dot_red.tpl
===================================================================
--- /extensions/rv_gmaps/trunk/template/markers/small_dot_red.tpl	(revision 12700)
+++ 	(revision )
@@ -1,8 +1,0 @@
-var icon = new google.maps.Icon();
-icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
-icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
-icon.iconSize = new google.maps.Size(12, 20);
-icon.shadowSize = new google.maps.Size(22, 20);
-icon.iconAnchor = new google.maps.Point(6, 20);
-icon.infoWindowAnchor = new google.maps.Point(5, 1);
-return icon;
