Skip to content

Instantly share code, notes, and snippets.

@dvidsilva
Created March 19, 2014 18:47
Show Gist options
  • Save dvidsilva/9648539 to your computer and use it in GitHub Desktop.
Save dvidsilva/9648539 to your computer and use it in GitHub Desktop.
Angular directive to embed google maps in your application
#put the map url in a map attribute in the dom element that has this directive.
#it will get the location from the map url and create an iframe
myApp.directive 'gMap', ->
restrict: "EA"
link: (scope, element, attrs)->
if attrs.map
re = /@(-?\d+\.?\d*,-?\d+\.?\d*),([\d]{1,2})z/gi
url = ''
attrs.map.replace re, (match, lat, z)->
z = z || 10
url = "https://www.google.com/maps/embed/v1/view?key={{developerkey}}&center=#{lat}+&zoom=#{z}"
code = '<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'+url+'"></iframe>'
if url isnt ''
element.html code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment