var myCenterPoint = new GLatLng(centerLat,centerLng);

		  function initialize() {
			var mapTypes = G_DEFAULT_MAP_TYPES;
			for(var i = 0; i < mapTypes.length; i++){
				mapTypes[i].getMaximumResolution = function(latlng){ return 14;};
				mapTypes[i].getMinimumResolution = function(latlng){ return 7;};
			}
			myMap = new GMap2(document.getElementById("map_canvas"),{mapTypes: mapTypes});
			myMap.setCenter(new GLatLng(centerLat,centerLng), 8); //Centrage de la carte (lat, long, zoom)
	        myMap.setUIToDefault();
	        var uiOptions = myMap.getDefaultUI();
			uiOptions.zoom.scrollwheel = false; //Désactive le zoom molette de la souris (pas pratique) 
			myMap.setUI(uiOptions);
			//Enlève les boutons pour changer de vue (plan, satellite, mixte ...)
	        myMap.removeMapType(G_PHYSICAL_MAP);
	        myMap.removeMapType(G_SATELLITE_MAP);
	        myMap.removeMapType(G_HYBRID_MAP);
	        myMap.removeMapType(G_NORMAL_MAP);
	        
			createCircle(myCenterPoint,initRadius);
		  }
	    
	    
		  var metric = false;
		  var singleClick = false;
		  var queryCenterOptions = new Object();
		  var queryLineOptions = new Object();
		
		//création des de l'icone de déplacement du cercle
		queryCenterOptions.icon = new GIcon();
		queryCenterOptions.icon.image = "images/centerArrow.png";
		queryCenterOptions.icon.iconSize = new GSize(20,20);
		queryCenterOptions.icon.shadowSize = new GSize(0, 0);
		queryCenterOptions.icon.iconAnchor = new GPoint(10, 10);
		queryCenterOptions.draggable = true;
		queryCenterOptions.bouncy = false;
		
		//création des de l'icone de redimensionnement du cercle
		queryLineOptions.icon = new GIcon();
		queryLineOptions.icon.image = "images/resizeArrow.png";
		queryLineOptions.icon.iconSize = new GSize(25,20);
		queryLineOptions.icon.shadowSize = new GSize(0, 0);
		queryLineOptions.icon.iconAnchor = new GPoint(12, 10);
		queryLineOptions.draggable = true;
		queryLineOptions.bouncy = false;
		
		function createCircle(point, radius) {
		  singleClick = false;
		  geoQuery = new GeoQuery();
		  geoQuery.initializeCircle(radius, point, myMap);
		  geoQuery.render();
		}
		
		function destination(orig, hdng, dist) {
		  var R = 6371; // earth's mean radius in km
		  var oX, oY;
		  var x, y;
		  var d = dist/R;  // d = angular distance covered on earth's surface
		  hdng = hdng * Math.PI / 180; // degrees to radians
		  oX = orig.x * Math.PI / 180;
		  oY = orig.y * Math.PI / 180;
		
		  y = Math.asin( Math.sin(oY)*Math.cos(d) + Math.cos(oY)*Math.sin(d)*Math.cos(hdng) );
		  x = oX + Math.atan2(Math.sin(hdng)*Math.sin(d)*Math.cos(oY), Math.cos(d)-Math.sin(oY)*Math.sin(y));
		
		  y = y * 180 / Math.PI;
		  x = x * 180 / Math.PI;
		  return new GLatLng(y, x);
		}
		
		function distance(point1, point2) {
		  var R = 6371; // earth's mean radius in km
		  var lon1 = point1.lng()* Math.PI / 180;
		  var lat1 = point1.lat() * Math.PI / 180;
		  var lon2 = point2.lng() * Math.PI / 180;
		  var lat2 = point2.lat() * Math.PI / 180;
		
		  var deltaLat = lat1 - lat2
		  var deltaLon = lon1 - lon2
		
		  var step1 = Math.pow(Math.sin(deltaLat/2), 2) + Math.cos(lat2) * Math.cos(lat1) * Math.pow(Math.sin(deltaLon/2), 2);
		  var step2 = 2 * Math.atan2(Math.sqrt(step1), Math.sqrt(1 - step1));
		  return step2 * R;
		}
		
		function GeoQuery() {
		
		}
		
		GeoQuery.prototype.CIRCLE='circle';
		GeoQuery.prototype.COLORS=["#0000ff", "#00ff00", "#ff0000"];
		var COLORI=0;
		
		GeoQuery.prototype = new GeoQuery();
		GeoQuery.prototype._map;
		GeoQuery.prototype._type;
		GeoQuery.prototype._radius;
		GeoQuery.prototype._dragHandle;
		GeoQuery.prototype._centerHandle;
		GeoQuery.prototype._polyline;
		GeoQuery.prototype._color ;
		GeoQuery.prototype._points;
		GeoQuery.prototype._dragHandlePosition;
		GeoQuery.prototype._centerHandlePosition;
		
		
		//création du cercle de recherche
		GeoQuery.prototype.initializeCircle = function(radius, point, map) {
		    this._type = this.CIRCLE;
		    this._radius = radius;
		    this._map = map;
		    this._dragHandlePosition = destination(point, 90, this._radius/1000);
		    this._dragHandle = new GMarker(this._dragHandlePosition, queryLineOptions);
		    this._centerHandlePosition = point;
		    this._centerHandle = new GMarker(this._centerHandlePosition, queryCenterOptions);
		    this._color = this.COLORS[COLORI++ % 3];
		    map.addOverlay(this._dragHandle);
		    map.addOverlay(this._centerHandle);
		    var myObject = this;
		    GEvent.addListener (this._dragHandle, "dragend", function() {myObject.updateCircle(1);});
		    GEvent.addListener (this._dragHandle, "drag", function() {myObject.updateCircle(1);});
		    GEvent.addListener(this._centerHandle, "dragend", function() {myObject.updateCircle(2);});
		    GEvent.addListener(this._centerHandle, "drag", function() {myObject.updateCircle(2);});
			document.moteur_recherche.latitude.value = this._centerHandlePosition.lat();
			document.moteur_recherche.longitude.value = this._centerHandlePosition.lng();
			document.moteur_recherche.rayon.value = ((this._radius * 3.2808399) / 5280).toFixed(1);
		}
		
		//Fonction appelé quand on redimensionne ou déplace le cercle
		GeoQuery.prototype.updateCircle = function (type) {
		    this._map.removeOverlay(this._polyline);
		    if (type==1) {
		      //on redimensionne le cercle
		      this._dragHandlePosition = this._dragHandle.getPoint();
		      this._radius = distance(this._centerHandlePosition, this._dragHandlePosition) * 1000;
		      this.render();
		    } else {
		      //on deplace le cercle
		      this._centerHandlePosition = this._centerHandle.getPoint();
		      this.render();
		      this._dragHandle.setPoint(this.getEast());
		      
		    }
			document.moteur_recherche.latitude.value = this._centerHandlePosition.lat();
			document.moteur_recherche.longitude.value = this._centerHandlePosition.lng();
			document.moteur_recherche.rayon.value = ((this._radius * 3.2808399) / 5280).toFixed(1);
		}
		
		//Fonction de remise en forme graphique du cercle lors de son deplacement ou redimensionnement
		GeoQuery.prototype.render = function() {
		  if (this._type == this.CIRCLE) {
		    this._points = [];
		    var distance = this._radius/1000;
		    for (i = 0; i < 72; i++) {
		      this._points.push(destination(this._centerHandlePosition, i * 360/72, distance) );
		    }
		    this._points.push(destination(this._centerHandlePosition, 0, distance) );
		    //this._polyline = new GPolyline(this._points, this._color, 6);
		    this._polyline = new GPolygon(this._points, this._color, 1, 1, this._color, 0.2);
		    this._map.addOverlay(this._polyline)
		  }
		}
		
		GeoQuery.prototype.getNorth = function() {
		  return this._points[0];
		}
		
		GeoQuery.prototype.getSouth = function() {
		  return this._points[(72/2)];
		}
		
		GeoQuery.prototype.getEast = function() {
		  return this._points[(72/4)];
		}
		
		GeoQuery.prototype.getWest = function() {
		  return this._points[(72/4*3)];
		}