forked from tristandunn/jquery-auto-geocoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.auto-geocoder.min.js
5 lines (5 loc) · 2.17 KB
/
jquery.auto-geocoder.min.js
1
2
3
4
5
(function(b){var f=new google.maps.Geocoder;b.fn.autoGeocoder=function(a){var c=b.fn.autoGeocoder;a=b.extend(true,{},c.defaults,a||{});c=a.setup||c.base;for(property in c)for(var e=c[property].length,d=0;d<e;d++)c[property][d].call(this,a);return this.trigger("auto-geocoder.initialize")};b.fn.autoGeocoder.base={initialize:[function(a){a.initial.center=google.maps.LatLng.call(this,a.initial.center);this.bind("auto-geocoder.initialize",function(){b(this).trigger("auto-geocoder.createMap").trigger("auto-geocoder.onKeyUp")})}],
createMap:[function(a){this.bind("auto-geocoder.createMap",function(){var c=b("<div>",{"class":a.className});a.position=="before"||a.position=="after"?b(this)[a.position](c):b(a.position).append(c);b(this).bind("keyup.auto-geocoder",function(){b(this).trigger("auto-geocoder.onKeyUp")});this.map=new google.maps.Map(c[0],a.initial)})}],onKeyUp:[function(a){this.bind("auto-geocoder.onKeyUp",function(){var c=this,e=b(c),d=b.trim(e.val()).replace(/\s+/g," ").toLowerCase();this.timeout&&clearTimeout(this.timeout);
if(!(this.previousAddress&&this.previousAddress==d))if(d=="")e.trigger("auto-geocoder.onGeocodeResult",[[],""]);else this.timeout=setTimeout(function(){c.previousAddress=d;f.geocode({address:d},function(g,h){e.trigger("auto-geocoder.onGeocodeResult",[g,h])})},a.delay)})}],onGeocodeResult:[function(a){this.get(0).marker=new google.maps.Marker;this.bind("auto-geocoder.onGeocodeResult",function(c,e,d){if(d==google.maps.GeocoderStatus.OK){if(a.success.zoom=="auto")this.map.fitBounds(e[0].geometry.viewport);
else{this.map.setZoom(a.success.zoom);this.map.setCenter(e[0].geometry.location)}this.marker.setPosition(e[0].geometry.location);this.marker.setMap(this.map);b(this).trigger("auto-geocoder.onGeocodeSuccess",[e,d])}else{this.marker&&this.marker.setMap(null);this.map.setZoom(a.initial.zoom);this.map.setCenter(a.initial.center);b(this).trigger("auto-geocoder.onGeocodeFailure",[e,d])}})}],onGeocodeSuccess:[],onGeocodeFailure:[]};b.fn.autoGeocoder.defaults={className:"jquery-auto-geocoder-map",position:"after",
delay:500,success:{zoom:"auto"},initial:{zoom:1,center:[34,0],draggable:false,mapTypeId:google.maps.MapTypeId.ROADMAP,mapTypeControl:false}}})(jQuery);