Created
February 13, 2014 00:01
-
-
Save lawrencejones/8967103 to your computer and use it in GitHub Desktop.
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 characters
################################################################################ | |
# Seed data | |
################################################################################ | |
CITIES = { # LAT, LONG | |
london: [51.5072, 0.1275] | |
manchester: [53.4667, 2.2333] | |
newcastle: [54.9740, 1.6132] | |
bristol: [51.4500, 2.5833] | |
southampton: [50.8970, 1.4042] | |
} | |
DEFAULT_CENTER = new google.maps.LatLng CITIES.london... | |
################################################################################ | |
# Holds current user location | |
################################################################################ | |
angular.module('google') | |
.factory 'CurrentLocation', -> | |
# List of callbacks waiting on resolved position | |
waiters = [] | |
resolved = false | |
new class CurrentLocation | |
# Uses html5 api to location current position. | |
constructor: -> | |
me = this | |
@latlng = DEFAULT_CENTER | |
navigator.geolocation.getCurrentPosition (pos) -> | |
if pos? | |
coords = [pos.coords.latitude, pos.coords.longitude] | |
@latlng = new google.maps.LatLng coords... | |
printMessage "Resolved current position #{@latlng}" | |
else | |
printMessage "Could not resolve current position [#{pos}]" | |
printMessage "Notifying #{waiters.length} waiters" | |
cb?(@latlng) for cb in waiters | |
# Adds a new callback to the queue | |
getLocation: (cb) -> | |
if not resolved then waiters.push cb | |
else cb?(@latlng) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment