Skip to content

Instantly share code, notes, and snippets.

@valentina-s
Created March 19, 2016 22:51
Show Gist options
  • Save valentina-s/14a683caa87c7df77396 to your computer and use it in GitHub Desktop.
Save valentina-s/14a683caa87c7df77396 to your computer and use it in GitHub Desktop.
JavaScript Snippet displaying a map and directions of a location in Seattle (based on the name)
<!DOCTYPE html>
<html>
<body>
<p>Discovery Park</p>
<button onclick="showMap('Discovery Park')">View Map</button>
<button onclick="showDirections('Discovery Park')">View Directions</button>
<script>
// Function showing the map
function showMap(name) {
new_name = name.split(" ").join("+")
address = "https://www.google.com/maps/place/"
googleMapsAddress = address.concat(new_name).concat(",seattle,wa")
window.open(googleMapsAddress);
}
//Function showing the directions
function showDirections(name) {
new_name = name.split(" ").join("+")
address = "https://www.google.com/maps/dir/Current+Location/"
googleMapsAddress = address.concat(new_name).concat(",seattle,wa")
window.open(googleMapsAddress);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment