From 12bb9a42d29153820b72138489ceeee634d52785 Mon Sep 17 00:00:00 2001 From: arnaucode Date: Wed, 22 Feb 2017 21:28:32 +0100 Subject: [PATCH] implemented geolocation to events create and on event show --- www/js/event.js | 8 +++--- www/js/newEvent.js | 55 +++++++++++++++++++++++++++++++++++-- www/templates/event.html | 7 +++-- www/templates/newEvent.html | 14 +++++++++- 4 files changed, 74 insertions(+), 10 deletions(-) diff --git a/www/js/event.js b/www/js/event.js index e007460..949c41f 100644 --- a/www/js/event.js +++ b/www/js/event.js @@ -36,12 +36,12 @@ angular.module('app.event', ['pascalprecht.translate', 'ui-leaflet']) $scope.markers.push({ lat: Number($scope.event.location.geo.lat), lng: Number($scope.event.location.geo.long), - message: $scope.event.location.name + message: $scope.event.location.direction }); $scope.center= { - lat: (Number($scope.travel.from.lat)+Number($scope.travel.to.lat))/2, - lng: (Number($scope.travel.from.long)+Number($scope.travel.to.long))/2, - zoom: 4 + lat: Number($scope.event.location.geo.lat), + lng: Number($scope.event.location.geo.long), + zoom: 16 }; } diff --git a/www/js/newEvent.js b/www/js/newEvent.js index 05639ff..238a3fb 100644 --- a/www/js/newEvent.js +++ b/www/js/newEvent.js @@ -1,9 +1,18 @@ -angular.module('app.newEvent', ['pascalprecht.translate']) +angular.module('app.newEvent', ['pascalprecht.translate', 'ui-leaflet']) -.controller('NewEventCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading, $filter) { +.controller('NewEventCtrl', function($scope, $http, $ionicModal, $timeout, + $ionicLoading, $filter, leafletData, leafletBoundsHelpers) { $scope.event={}; $scope.event.categories=[{name: "prova"}]; + $scope.event.location={ + direction: "", + geo: { + lat: "", + long: "", + name: "" + } + }; $scope.postEvent = function(){ $http({ url: urlapi + 'events', @@ -11,6 +20,7 @@ angular.module('app.newEvent', ['pascalprecht.translate']) data: $scope.event }) .then(function(data) { + $scope.event={}; window.location.href="#/app/events"; }, function(response) { // optional @@ -18,4 +28,45 @@ angular.module('app.newEvent', ['pascalprecht.translate']) console.log(response); }); }; + + /* map */ + + $scope.center= { + lat: 0, + lng: 0, + zoom: 1 + }; + $scope.markers=new Array(); + $scope.tiles= { + url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", + options: { + attribution: 'OpenStreetMap contributors' + } + }; + $scope.getGeo = function(){ + + $scope.markers=[]; + console.log($scope.event.location.direction); + $http.get('http://nominatim.openstreetmap.org/search?q=' + $scope.event.location.direction + '&format=json&limit=1') + .then(function(data) { + console.log(data); + if(data.data[0]) + { + $scope.event.location.geo.lat=data.data[0].lat; + $scope.event.location.geo.long=data.data[0].lon; + //$scope.newtravel.from.name=data.data[0].display_name; + $scope.markers.push({ + lat: Number(data.data[0].lat), + lng: Number(data.data[0].lon), + message: $scope.event.location.direction + }); + $scope.center= { + lat: Number(data.data[0].lat), + lng: Number(data.data[0].lon), + zoom: 16 + }; + } + }); + + }; }); diff --git a/www/templates/event.html b/www/templates/event.html index 471ee0f..404fd32 100644 --- a/www/templates/event.html +++ b/www/templates/event.html @@ -5,7 +5,7 @@

{{event.user.username}}

{{event.user.shortDescription}}

-
+
@@ -14,10 +14,11 @@

{{event.date | date: 'HH:mm, dd/MM/yyyy'}}

- + +
-
+
Post new event!