Skip to content

Instantly share code, notes, and snippets.

@jouderianjr
Last active August 29, 2015 14:27
Show Gist options
  • Save jouderianjr/accca5aec646fe678fc5 to your computer and use it in GitHub Desktop.
Save jouderianjr/accca5aec646fe678fc5 to your computer and use it in GitHub Desktop.
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
var app = angular.module('starter', ['ionic', 'starter.services']);
app.controller('teste', function($scope, $ionicLoading, Occurrence){
console.log('vixi doido');
$scope.hasButton = true;
$scope.state = 'buttons';
$scope.saveState = false;
$scope.points = Occurrence.getPoints();
google.maps.event.addDomListener(window, 'load', function() {
var myLatlng = new google.maps.LatLng(37.3000, -120.4833);
var mapOptions = {
center: myLatlng,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true
};
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
console.log(Occurrence.getPoints());
angular.forEach($scope.points, function (point, key) {
var marker = new google.maps.Marker({
position: point,
map: map,
title: 'WOOOOOOWWW'
});
});
$scope.map = map;
$scope.centerAtPosition();
});
$scope.$watch('state', function() {
console.log('dentro do watch do state');
if($scope.state == 'choosePlace'){
console.log('choosePlace')
$scope.map.addListener('click', function(e) {
var marker = new google.maps.Marker({
position: e.latLng,
map: $scope.map,
draggable: true
});
$scope.map.panTo(e.latLng);
$scope.latLng = e.latLng;
$scope.saveState = true;
$scope.state = 'saveState';
});
}
})
$scope.add = function () {
$scope.hasButton = false;
$scope.state = 'choosePlace';
}
$scope.savePoint = function () {
console.log('saveee')
}
$scope.centerAtPosition = function () {
$scope.loading = $ionicLoading.show({
content: 'Getting current location...',
showBackdrop: false
});
navigator.geolocation.getCurrentPosition(function (pos) {
console.log('Got pos', pos);
$scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
$ionicLoading.hide();
}, function (error) {
alert('Unable to get location: ' + error.message);
});
}
})
// .config(function($stateProvider, $urlRouterProvider) {
// $stateProvider
// .state('app', {
// url: '/app',
// abstract: true,
// templateUrl: 'templates/menu.html',
// controller: 'AppCtrl'
// })
// })
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment