Browse Source

Agregado de funcion que pasado un par de coordenadas retorna la direccion

Your Name 7 năm trước cách đây
mục cha
commit
ede6c71729
1 tập tin đã thay đổi với 32 bổ sung8 xóa
  1. 32 8
      Resources/public/js/leaflet-map-widget.js

+ 32 - 8
Resources/public/js/leaflet-map-widget.js

@@ -51,8 +51,7 @@ $(document).ready(function () {
     });
 });
 
-function setDataValue()
-{
+function setDataValue() {
     var jsonParseData = {};
     var dataValue = $('[name$="[extraData]"]').val();
     if (dataValue) {
@@ -67,20 +66,22 @@ function setDataValue()
     $('[name$="[extraData]"]').val(stringifyData);
     $('[name$="[map]"]').val(stringifyData);
     // si existe la funcion la llamo. Actualiza la distancia entre el punto seleccionado y los naps.
-    if(typeof calcularDistanciaNap === 'function'){
+    if (typeof calcularDistanciaNap === 'function') {
         calcularDistanciaNap();
     }
+    // si existe la funcion la llamo. Actualiza direccion del cliente.
+    if (typeof updateAddressClient === 'function') {
+        updateAddressClient();
+    }
 }
 
-function googleGeocoding(text, callResponse)
-{
+function googleGeocoding(text, callResponse) {
     geocoder.geocode({address: text}, callResponse);
 }
 
-function formatJSON(rawjson)
-{
+function formatJSON(rawjson) {
     var json = {},
-            key;
+        key;
     for (var i in rawjson) {
         key = rawjson[i].formatted_address;
         loc = new L.latLng(rawjson[i].geometry.location.lat(), rawjson[i].geometry.location.lng());
@@ -88,4 +89,27 @@ function formatJSON(rawjson)
     }
 
     return json;
+}
+
+/**
+ * Funcion que obtiene la direccion a partir de las coordenadas.
+ * @param lat
+ * @param lng
+ * @param callback Funcion de callback el primer parametro contiene el status y el segundo un objeto json.
+ */
+function geocodeLatLng(lat, lng, callback) {
+    var latlng = {lat: lat, lng: lng};
+    geocoder.geocode({'location': latlng}, function (results, status) {
+        if (status == google.maps.GeocoderStatus.OK) {
+            if (results[0]) {
+                callback(true, {
+                    complete: results[0].formatted_address
+                });
+            } else {
+                callback(false, status.status);
+            }
+        } else {
+            callback(false, status.status);
+        }
+    });
 }