css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <h1>A super-simple geolocatio&#8203;n example</h1>
<i class="fa fa-map-marker"></i>
<button class="pure-button pure-button-primary">Get my location</button>
<div class="result"></div>
<span>see link in "details" for more information</span>
              @import url(https://fonts.googleapis.com/css?family=Open+Sans:400);
@import url(//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css);
@import url(https://yui.yahooapis.com/pure/0.3.0/pure-min.css);

  background: #222;
  background: #fff;
  font-family: 'Open Sans', sans-serif;
  max-width: 380px;
  border: 1px solid #ccc;
  border-radius: 5px;
  box-shadow: 0 0 1px #000; 
  margin: 1em auto;
  padding: 0 1em 1em 1em;
  text-align: center;
  font-size: 10em;
  color: #cf483e;
  text-shadow: 0 0 1px #000; 
  animation: bounce 1s linear 3;
  box-shadow: 0 0 1px #000; 
  margin: 2em 2em 1em 2em;
.result img{
  margin-top: 1em;
  border: 1px solid #333; 
  font-size: 3em;
span{font-size:.7em;color: #777;}
@keyframes bounce {
	/* thx to https://github.com/daneden/animate.css */
  0%, 20%, 50%, 80%, 100% {transform: translateY(0);}
	40% {transform: translateY(-15px);}
	60% {transform: translateY(-7px);}

              /** NOTE: uses jQuery for quick & easy DOM manipulation **/

function getLocation(){
  var msg; 

  first, test for feature support
  if('geolocation' in navigator){
    // geolocation is supported :)
    // no geolocation :(
    msg = "Sorry, looks like your browser doesn't support geolocation";
    outputResult(msg); // output error message
    $('.pure-button').removeClass('pure-button-primary').addClass('pure-button-success'); // change button style

  requestLocation() returns a message, either the users coordinates, or an error message
  function requestLocation(){
    getCurrentPosition() below accepts 3 arguments:
    a success callback (required), an error callback  (optional), and a set of options (optional)
    var options = {
      // enableHighAccuracy = should the device take extra time or power to return a really accurate result, or should it give you the quick (but less accurate) answer?
      enableHighAccuracy: false,
      // timeout = how long does the device have, in milliseconds to return a result?
      timeout: 5000,
      // maximumAge = maximum age for a possible previously-cached position. 0 = must return the current position, not a prior cached position
      maximumAge: 0
    // call getCurrentPosition()
    navigator.geolocation.getCurrentPosition(success, error, options); 
    // upon success, do this
    function success(pos){
      // get longitude and latitude from the position object passed in
      var lng = pos.coords.longitude;
      var lat = pos.coords.latitude;
      // and presto, we have the device's location!
      msg = 'You appear to be at longitude: ' + lng + ' and latitude: ' + lat  + '<img src="https://maps.googleapis.com/maps/api/staticmap?zoom=15&size=300x300&maptype=roadmap&markers=color:red%7Clabel:A%7C' + lat + ',' + lng+ '&sensor=false">';
      outputResult(msg); // output message
      $('.pure-button').removeClass('pure-button-primary').addClass('pure-button-success'); // change button style
    // upon error, do this
    function error(err){
      // return the error message
      msg = 'Error: ' + err + ' :(';
      outputResult(msg); // output button
      $('.pure-button').removeClass('pure-button-primary').addClass('pure-button-error'); // change button style
  } // end requestLocation();

  outputResult() inserts msg into the DOM  
  function outputResult(msg){
} // end getLocation()

// attach getLocation() to button click
$('.pure-button').on('click', function(){
  // show spinner while getlocation() does its thing
  $('.result').html('<i class="fa fa-spinner fa-spin"></i>');
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................