-
Notifications
You must be signed in to change notification settings - Fork 8
/
jquery.geolocation.edit.min.js
10 lines (10 loc) · 3.05 KB
/
jquery.geolocation.edit.min.js
1
2
3
4
5
6
7
8
9
10
// jQuery geolocation.edit plugin v0.0.16 (2015-10-16)
// Copyright (c) 2012 Milos Popovic <[email protected]>
// Freely distributable under the MIT license.
// see: http://github.com/miloss/jquery-geolocation-edit
(function(a){var k,h=[],g={main:function(c){var b=this;if("undefined"===typeof c.lat||"undefined"===typeof c.lng)a.error("Please provide 'lat' and 'lng' options for jQuery.geolocate");else if("undefined"===typeof google||"undefined"===typeof google.maps)h.push(function(){a(b).geolocate(c)}),k();else{var d=a.extend(!0,{address:[],changeOnEdit:!1,readOnlyMap:!1,mapOptions:{zoom:14,mapTypeId:google.maps.MapTypeId.ROADMAP,mapTypeControl:!1,streetViewControl:!1},markerOptions:{draggable:!0,animation:google.maps.Animation.DROP},
geoCallback:function(){}},c);a(this).data("opts",d);var f=parseFloat(a(d.lat).val()),e=parseFloat(a(d.lng).val());isNaN(f)&&(f=0);isNaN(e)&&(e=0);f=new google.maps.LatLng(f,e);a(this).geolocate({},"initMap",f);d.changeOnEdit&&(a(d.lat).change(function(){a(b).geolocate({},"updateLatLng",d)}),a(d.lng).change(function(){a(b).geolocate({},"updateLatLng",d)}));f=d.address.length;for(e=0;e<f;e++)a(d.address[e]).change(function(){a(b).geolocate({},"callGeocoding")})}},initMap:function(c){var b=a(this).get(0),
d=google.maps,f=a.data(b,"opts"),e=new d.Map(b,a.extend({center:c},f.mapOptions));c=a.extend({map:e,position:c},f.markerOptions);var l=new d.Marker(c);a.data(b,"map",e);a.data(b,"marker",l);d.event.addListener(l,"dragend",function(){a(b).geolocate({},"getMarkerLocation")});f.readOnlyMap||d.event.addListener(e,"click",function(c){l.setPosition(c.latLng);a(b).geolocate({},"getMarkerLocation")})},callGeocoding:function(){for(var c=a(this).get(0),b=a.data(c,"opts"),d=b.address.length,f=b.geoCallback,
e="";d--;)e+=a(b.address[d]).val();(new google.maps.Geocoder).geocode({address:e},function(b,d){var e,g,h,k;f(b,d);g=b[0];"undefined"!==typeof g&&(h=a.data(c,"map"),k=a.data(c,"marker"),e=g.geometry.location,h.panToBounds(g.geometry.viewport),h.panTo(e),k.setPosition(e),a(c).geolocate({},"getMarkerLocation"))})},getMarkerLocation:function(){var c=a.data(a(this).get(0),"marker"),b=a.data(a(this).get(0),"opts"),c=c.getPosition();a(b.lat).val(c.lat());a(b.lng).val(c.lng())},updateLatLng:function(c){var b=
a(this).get(0),d=a(c.lat).val();c=a(c.lng).val();d=new google.maps.LatLng(d,c);c=a.data(b,"map");b=a.data(b,"marker");c.panTo(d);b.setPosition(d)}};a.fn.geolocate=function(c,b){var d=Array.prototype.slice;if("undefined"===typeof b){if("string"===typeof c&&"undefined"!==typeof g[c])return g[c].apply(this,d.call(arguments,1));a(this).geolocate({},"main",c)}else{if(g[b])return g[b].apply(this,d.call(arguments,2));a.error("Method "+b+" does not exist on jQuery.geolocate")}return this};a.fn.geolocateGMapsLoaded=
function(){for(;h.length;)h.shift()()};k=function(){var a=!1;return function(){var b;a||(a=!0,b=document.createElement("script"),b.type="text/javascript",b.src=("https:"==window.location.protocol?"https":"http")+"://maps.googleapis.com/maps/api/js?sensor=false&callback=jQuery.fn.geolocateGMapsLoaded",document.body.appendChild(b))}}()})(jQuery);