arnaucube
arnaucube/openEventsPlatformAppPublic Self-hosted repository
openEventsPlatformApp/www/js/place.js
www/js/place.jsRaw
 1angular.module('app.place', ['pascalprecht.translate', 'ui-leaflet'])
 2
 3.controller('PlaceCtrl', function($scope, $http, $ionicModal, $timeout,
 4        $ionicLoading, $filter, leafletData, leafletBoundsHelpers) {
 5
 6    $scope.center= {
 7        lat: 0,
 8        lng: 0,
 9        zoom: 1
10    };
11    $scope.markers=new Array();
12    $scope.tiles= {
13        url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
14        options: {
15            attribution: '<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
16        }
17    };
18    $scope.place={
19        location:{
20            direction:"",
21            geo:{
22                lat:"",
23                long:""
24            }
25        }
26    };
27    $scope.getGeo = function(){
28        $scope.markers=[];
29        console.log($scope.place.location.direction);
30        $http.get('http://nominatim.openstreetmap.org/search?q=' + $scope.place.location.direction + '&format=json&limit=1')
31        .then(function(data) {
32            console.log(data);
33            if(data.data[0])
34            {
35                $scope.place.location.geo.lat=data.data[0].lat;
36                $scope.place.location.geo.long=data.data[0].lon;
37                //$scope.newtravel.from.name=data.data[0].display_name;
38                $scope.markers.push({
39                    lat: Number(data.data[0].lat),
40                    lng: Number(data.data[0].lon),
41                    message: $scope.place.location.direction
42                });
43                $scope.center= {
44                    lat: Number(data.data[0].lat),
45                    lng: Number(data.data[0].lon),
46                    zoom: 16
47                };
48            }
49        });
50    };
51});