Created
March 19, 2014 18:47
-
-
Save dvidsilva/9648539 to your computer and use it in GitHub Desktop.
Angular directive to embed google maps in your application
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
#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}}¢er=#{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