angular.module('starter.directives',[]).directive('map',function(){return{restrict:'E',scope:{onCreate:'&'},link:function($scope,$element,$attr){functioninitialize(){varmapOptions={center:newgoogle.maps.LatLng(43.07493,-89.381388),zoom:16,mapTypeId:google.maps.MapTypeId.ROADMAP};varmap=newgoogle.maps.Map($element[0],mapOptions);$scope.onCreate({map:map});// Stop the side bar from dragging when mousedown/tapdown on the mapgoogle.maps.event.addDomListener($element[0],'mousedown',function(e){e.preventDefault();returnfalse;});}if(document.readyState==="complete"){initialize();}else{google.maps.event.addDomListener(window,'load',initialize);}}}});
angular.module('starter.controllers',[]).controller('MapCtrl',function($scope,$ionicLoading){$scope.mapCreated=function(map){$scope.map=map;};$scope.direction=function(){if(!$scope.map){return;}$scope.loading=$ionicLoading.show({template:'Getting current location...',showBackdrop:false});navigator.geolocation.getCurrentPosition(function(pos){console.log('Got pos',pos);center=newgoogle.maps.LatLng(37.772323,-122.214897);target=newgoogle.maps.LatLng(37.771923,-122.219339);$scope.map.setCenter(center);vardirectionsDisplay=newgoogle.maps.DirectionsRenderer();vardirectionsService=newgoogle.maps.DirectionsService();directionsDisplay.setMap($scope.map);varrequest={origin:center,destination:target,travelMode:google.maps.TravelMode.DRIVING};directionsService.route(request,function(response,status){if(status==google.maps.DirectionsStatus.OK){directionsDisplay.setDirections(response);}});$ionicLoading.hide();},function(error){alert('Unable to get location: '+error.message);});}$scope.centerOnMe=function(){console.log("Centering");if(!$scope.map){return;}$scope.loading=$ionicLoading.show({template:'Getting current location...',showBackdrop:false});navigator.geolocation.getCurrentPosition(function(pos){console.log('Got pos',pos);center=newgoogle.maps.LatLng(pos.coords.latitude,pos.coords.longitude);$scope.map.setCenter(center);varmarker=newgoogle.maps.Marker({position:center,map:$scope.map,title:'Hello World!'});$ionicLoading.hide();},function(error){alert('Unable to get location: '+error.message);});};});