Last active
August 29, 2015 14:23
-
-
Save kcliu/383f7ad85ce535639ae2 to your computer and use it in GitHub Desktop.
This file contains 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
'use strict' | |
# return: google map object wrapped by promise | |
gmapData = ($q) -> | |
geoCode: (lat, lng, addr) -> | |
# 台北市大安區復興南路一段205號6樓 | |
# lat: 25.0395041 | |
# lng: 121.5439738 | |
deferred = $q.defer() | |
# [not not] syntax is for int transformer | |
if ~~lat isnt 999 and ~~lng isnt 999 | |
position = new google.maps.LatLng(lat, lng) | |
deferred.resolve position | |
else | |
geocoder = new google.maps.Geocoder() | |
geocoder.geocode | |
'address': addr | |
, (res, status) -> | |
if status is google.maps.GeocoderStatus.OK | |
deferred.resolve res[0].geometry.location | |
else | |
deferred.reject "Geocode failed duo to: #{status}" | |
deferred.promise | |
deferred.promise | |
angular.module('accupass.services') | |
.service("gmapData", ['$q', gmapData]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment