Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/directives.js"></script>
<script src="js/markersService.js"></script>
</head>

<body ng-app="starter" ng-controller="MapCtrl">
Expand Down
2 changes: 1 addition & 1 deletion js/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module('starter', ['ionic', 'starter.controllers', 'starter.directives'])
angular.module('starter', ['ionic', 'starter.controllers', 'starter.directives','starter.service'])

.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
Expand Down
10 changes: 7 additions & 3 deletions js/controllers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
angular.module('starter.controllers', [])

.controller('MapCtrl', function($scope, $ionicLoading) {
.controller('MapCtrl', function($scope, $ionicLoading,markersMgr) {
$scope.mapCreated = function(map) {
$scope.map = map;
};
Expand All @@ -17,8 +17,12 @@ angular.module('starter.controllers', [])
});

navigator.geolocation.getCurrentPosition(function (pos) {
console.log('Got pos', pos);
$scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
console.log('Got pos', pos);
// remove old marker(s)
markersMgr.removeMarkers();
var position = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
$scope.map.setCenter(position);
markersMgr.addMarker($scope.map,position);
$scope.loading.hide();
}, function (error) {
alert('Unable to get location: ' + error.message);
Expand Down
9 changes: 5 additions & 4 deletions js/directives.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
angular.module('starter.directives', [])

.directive('map', function() {
.directive('map',function(markersMgr) {
return {
restrict: 'E',
scope: {
onCreate: '&'
},
link: function ($scope, $element, $attr) {
function initialize() {
var position = new google.maps.LatLng(43.07493, -89.381388);
var mapOptions = {
center: new google.maps.LatLng(43.07493, -89.381388),
center: position,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map($element[0], mapOptions);

var map = new google.maps.Map($element[0], mapOptions);
markersMgr.addMarker(map,position);
$scope.onCreate({map: map});

// Stop the side bar from dragging when mousedown/tapdown on the map
Expand Down
21 changes: 21 additions & 0 deletions js/markersService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
angular.module('starter.service', [])

.service('markersMgr',function(){

this.markers = [];

this.addMarker = function(map,position){
var marker = new google.maps.Marker({
position: position,
map: map
});
this.markers.push(marker);
};

this.removeMarkers = function(){
angular.forEach(this.markers, function(value,key){
value.setMap(null);
});
};

});