Forked from joshmcarthur/example_controller.js.coffee
Created
November 13, 2013 21:13
Revisions
-
joshmcarthur created this gist
Jul 6, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ ExampleController = ($scope, LocationService) -> LocationService.locate().then (position) -> $scope.position = position ExampleController.$inject = ["$scope", "LocationService"] YourAngularApp.controller("ExampleController", ExampleController) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ <div ng-controller="ExampleController"> <div class="well" ng-show="position"> <h1>{{position.address}}</h1> <span>Within {{position.coords.accuracy}}m</span> </div> <div ng-hide="position"> <h1>Finding your position...</h1> </div> </div> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ LocationService = ($q, $rootScope, ReverseGeolocationService) -> locate = -> defer = $q.defer() navigator.geolocation.getCurrentPosition( (position) -> ReverseGeolocationService.findAddress( position.coords.latitude, position.coords.longitude ).then (address) -> position = {coords: position.coords} position.address = address defer.resolve(position) , (error) -> defer.reject(error) ) defer.promise {locate: locate} LocationService.$inject = ["$q", "$rootScope", "ReverseGeolocationService"] YourAngularApp.factory("LocationService", LocationService) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ ReverseGeolocationService = ($q, $rootScope, $http) -> url = (latitude, longitude) -> "http://nominatim.openstreetmap.org/reverse?format=json&lat=#{latitude}&lon=#{longitude}&zoom=18&addressdetails=0" findAddress = (latitude, longitude) -> defer = $q.defer() $http(method: 'GET', url: url(latitude, longitude)) .success (data) -> defer.resolve(data.display_name) .error (status) -> defer.rejct(status) defer.promise {findAddress: findAddress} ReverseGeolocationService.$inject = ["$q", "$rootScope", "$http"] YourAngularApp.factory "ReverseGeolocationService", ReverseGeolocationService