function GReverseGeocoder(b){this.map=b;this.gdirections=new GDirections();this.geocoder=new GClientGeocoder();this.bounds=0.1;this.lastpoint=null;this.closestonroad=null;this.experimental=false;this.ad="";this.step=10;this.start=1;this.gdirectionsrefine=new GDirections();GEvent.bind(this.gdirections,"error",this,this.handleError);GEvent.bind(this.gdirections,"load",this,this.processDirection);GEvent.bind(this.gdirectionsrefine,"error",this,this.handleError);GEvent.bind(this.gdirectionsrefine,"load",this,this.processDirectionRefine)}GReverseGeocoder.prototype.reverseGeocode=function(b){this.lastpoint=b;this.closestonroad=null;this.gdirections.clear();this.gdirections.loadFromWaypoints([b.toUrlValue(6),b.toUrlValue(6)],{getSteps:true,locale:"GB",getPolyline:true})};GReverseGeocoder.prototype.getStatus=function(){return this.gdirections.getStatus()};GReverseGeocoder.prototype.handleError=function(){GEvent.trigger(this,"error",this.lastpoint)};GReverseGeocoder.prototype.processDirection=function(){var j=this;if(this.gdirections.getPolyline()!=null){this.closestonroad=this.gdirections.getPolyline().getVertex(0)}if(this.gdirections.getNumRoutes()!=0){var h=this.getStreet(this.gdirections.getGeocode(0).address);var g=new GLatLng(Number(this.lastpoint.lat())-this.bounds,Number(this.lastpoint.lng())-this.bounds);var i=new GLatLng(Number(this.lastpoint.lat())+this.bounds,Number(this.lastpoint.lng())+this.bounds);var f=new GLatLngBounds(g,i);this.geocoder.setViewport(f);this.geocoder.getLocations(h,function(b){var a=j.getBestMatchingPlacemark(b);if(a!=null){if(j.experimental){j.ad=a.address;j.step=10;j.start=1;j.houseNumberSearch()}else{GEvent.trigger(j,"load",a)}}else{j.handleError()}})}};GReverseGeocoder.prototype.getBestMatchingPlacemark=function(m){if(!m||m.Status.code!=200){return null}var l=-1;var j=1000000;for(var k=0;k<m.Placemark.length;k++){var h=m.Placemark[k];var i=new GLatLng(h.Point.coordinates[1],h.Point.coordinates[0]);var n=this.lastpoint.distanceFrom(i);if(n<j){l=k;j=n}}if(l<0){return null}m.Placemark[l].RequestPoint={coordinates:[this.lastpoint.lng(),this.lastpoint.lat()]};m.Placemark[l].PointOnRoad={coordinates:[this.closestonroad.lng(),this.closestonroad.lat()]};m.Placemark[l].Distance=j;m.Placemark[l].DistanceOnRoad=this.closestonroad.distanceFrom(new GLatLng(m.Placemark[l].Point.coordinates[1],m.Placemark[l].Point.coordinates[0]));return m.Placemark[l]};GReverseGeocoder.prototype.processDirectionRefine=function(){var l=this.gdirectionsrefine.getNumGeocodes();var q=-1;var o=100;for(var p=1;p<l;p++){var r=this.gdirectionsrefine.getGeocode(p);var j=new GLatLng(r.Point.coordinates[1],r.Point.coordinates[0]);if(r.AddressDetails.Accuracy==8){var i=this.lastpoint.distanceFrom(j);if(i<o){q=p;o=i}}}if(q<0){if(this.start+(24*this.step)<2000){this.start=this.start+(25*this.step);this.houseNumberSearch()}else{this.handleError()}}else{if(this.step==1){var n=this.gdirectionsrefine.getGeocode(q);n.RequestPoint={coordinates:[this.lastpoint.lng(),this.lastpoint.lat()]};n.PointOnRoad={coordinates:[this.closestonroad.lng(),this.closestonroad.lat()]};n.Distance=o;n.DistanceOnRoad=this.closestonroad.distanceFrom(new GLatLng(n.Point.coordinates[1],n.Point.coordinates[0]));GEvent.trigger(this,"load",n)}else{var r=this.gdirectionsrefine.getGeocode(q);var m=this.start+(q*this.step);this.start=m-10;this.step=1;this.houseNumberSearch()}}};GReverseGeocoder.prototype.houseNumberSearch=function(){this.gdirectionsrefine.clear();this.gdirectionsrefine.loadFromWaypoints([(""+(this.start+(0*this.step))+" ")+this.ad,(""+(this.start+(1*this.step))+" ")+this.ad,(""+(this.start+(2*this.step))+" ")+this.ad,(""+(this.start+(3*this.step))+" ")+this.ad,(""+(this.start+(4*this.step))+" ")+this.ad,(""+(this.start+(5*this.step))+" ")+this.ad,(""+(this.start+(6*this.step))+" ")+this.ad,(""+(this.start+(7*this.step))+" ")+this.ad,(""+(this.start+(8*this.step))+" ")+this.ad,(""+(this.start+(9*this.step))+" ")+this.ad,(""+(this.start+(10*this.step))+" ")+this.ad,(""+(this.start+(11*this.step))+" ")+this.ad,(""+(this.start+(12*this.step))+" ")+this.ad,(""+(this.start+(13*this.step))+" ")+this.ad,(""+(this.start+(14*this.step))+" ")+this.ad,(""+(this.start+(15*this.step))+" ")+this.ad,(""+(this.start+(16*this.step))+" ")+this.ad,(""+(this.start+(17*this.step))+" ")+this.ad,(""+(this.start+(18*this.step))+" ")+this.ad,(""+(this.start+(19*this.step))+" ")+this.ad,(""+(this.start+(20*this.step))+" ")+this.ad,(""+(this.start+(21*this.step))+" ")+this.ad,(""+(this.start+(22*this.step))+" ")+this.ad,(""+(this.start+(23*this.step))+" ")+this.ad,(""+(this.start+(24*this.step))+" ")+this.ad],{getSteps:true,locale:"GB"})};GReverseGeocoder.prototype.getStreet=function(b){if(b==null){return null}if((b!=null)&&(b.indexOf("/")>0)){b=b.split("/");if(isNaN(b[0].charAt(1))){b=b[0]}else{b=b[1]}}return b};GReverseGeocoder.prototype.setExperimentalHouseNumber=function(b){this.experimental=b};GReverseGeocoder.prototype.getPlacemarkProperty=function(f,e){for(var g in f){if((g==e)){return String(f[g])}else{if(typeof(f[g])=="object"){var h=this.getPlacemarkProperty(f[g],e);if(h!=null){return h}}}}return null};