Skip to content

Instantly share code, notes, and snippets.

@lawrencejones
Created February 13, 2014 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawrencejones/8967103 to your computer and use it in GitHub Desktop.
Save lawrencejones/8967103 to your computer and use it in GitHub Desktop.
################################################################################
# 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