Juan Carlos Picado Herrera avatar Juan Carlos Picado Herrera committed da0580c

Geolocation support in progress

Comments (0)

Files changed (5)

enme-js/resources-enme-war/src/main/resources/resource/js/me/core/support/GeolocationSupport.js

+define([
+     "dojo/_base/declare",
+     "me/core/enme"],
+    function(
+    declare,
+    _ENME) {
+
+    'use strict';
+
+
+  /**
+    * Represent a geo location
+    * @property lat latitude
+    * @property long longitude
+    * @method Location
+    */
+   var Location = function(lat, lng) {
+      this.lat = lat || 0.0;
+      this.lng = lng || 0.0;
+   };
+
+   Location.prototype = {
+
+      /**
+       * Get the latitude.
+       * @method
+       */
+      getLatitude : function() {
+        return this.lng;
+      },
+
+      /**
+       * Get the latitude.
+       * @method
+       */
+      getLongitude : function() {
+        return this.lat;
+      }
+   };
+
+  /**
+   * Geolocation support
+   * @method
+   */
+  var GeoLocationSupport = function() {
+       var parent = this;
+       this.location = null;
+       try {
+          if (Modernizr.geolocation) {
+              var geo_success = function(position) {
+                  console.info("dddd", position.coords.latitude, position.coords.longitude);
+              };
+
+              var geo_error = function() {
+                  console.error("Sorry, no position available.");
+              };
+
+              var geo_options = {
+                enableHighAccuracy: true,
+                maximumAge        : 30000,
+                timeout           : 27000
+              };
+
+              var wpid = navigator.geolocation.watchPosition(geo_success, geo_error, geo_options);
+          } else {
+              parent.location = new Location();
+          }
+       } catch(error) {
+          console.info("error geo object", error);
+       }
+
+  };
+
+  GeoLocationSupport.prototype = {
+
+    /**
+     * Return a boolean response if the objects contains a longitud and latitude.
+     * @method
+     */
+    isLocated : function() {
+        return this.isLocated || false;
+    },
+
+    /**
+     * Return the location Object.
+     * @method
+     */
+    getLocation : function() {
+        return this.position;
+    }
+  };
+
+  return GeoLocationSupport;
+});

enme-js/resources-enme-war/src/main/resources/resource/js/me/web/widget/geo/BasicGeoWidget.js

+/*
+ * Copyright 2013 encuestame
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/***
+ *  @author juanpicado19D0Tgm@ilDOTcom
+ *  @version 1.146
+ *  @module UI
+ *  @namespace Widget
+ *  @class Message
+ */
+define([
+     "dojo/_base/declare",
+     "dijit/_WidgetBase",
+     "dijit/_TemplatedMixin",
+     "dijit/_WidgetsInTemplateMixin",
+     "me/core/main_widgets/EnmeMainLayoutWidget",
+     "me/core/enme",
+     "me/core/support/GeolocationSupport",
+     "dojo/text!me/web/widget/geo/templates/basic-geo-template.html"],
+    function(
+    declare,
+    _WidgetBase,
+    _TemplatedMixin,
+    _WidgetsInTemplateMixin,
+    main_widget,
+    _ENME,
+    GeolocationSupport,
+     template) {
+
+  return declare([ _WidgetBase, _TemplatedMixin, main_widget, _WidgetsInTemplateMixin], {
+
+     /**
+      * template string.
+      * @property
+      */
+     templateString : template,
+
+      /**
+       * Post create
+       * @method postCreate
+       */
+      postCreate : function () {
+         var geolocationSupport = new GeolocationSupport();
+         console.log("geo", geolocationSupport);
+         if (geolocationSupport.isLocated()) {
+             console.log("geolocationSupport", geolocationSupport.getLocation());
+         }
+      }
+  });
+});

enme-js/resources-enme-war/src/main/resources/resource/js/me/web/widget/geo/templates/basic-geo-template.html

+<div>
+	My location is ...
+</div>

enme-war/enme-views/src/main/webapp/WEB-INF/views/tweetpoll/decorators/completed.jsp

                     <spring:message code="tweetpoll.votes.link" />
                 </a>
             </div>
+            <!-- <div data-dojo-type="me/web/widget/geo/BasicGeoWidget"> </div> -->
         </div>
 
     </section>

enme-war/enme-views/src/main/webapp/WEB-INF/views/tweetpoll/decorators/voted.jsp

                     <spring:message code="tweetpoll.votes.link" />
                 </a>
             </div>
+            <div data-dojo-type="me/web/widget/geo/BasicGeoWidget"> </div>
         </div>
 
     </section>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.