Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="container">
  <div class="inner-container">
    <div class="box box-50">
      <div class="boxin">
        <div class="header">
          <h3>HTML5 Static Map Geo-Location</h3>
        </div>
        <div class="content">
          <ul class="simple">
            <li class="even">
              <span id="msg"></span>
            </li>
            <li class="odd">
              <strong>Your Latitude</strong>
              <span id="lat"></span>
            </li>
            <li class="even">
              <strong>Your Longitude</strong>
              <span id="lng"></span>
            </li>
            <li class="odd">
              <strong>Accuracy (in Meters)</strong>
              <span id="acc"></span>
            </li>
          </ul>
          <div id="map">
            Note: May take a few seconds to get the location.
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

              
            
!

CSS

              
                @import url("http://www.codediesel.com/demos/geolocation/html5-geo/blue.css");


#msg {
  font-weight: bold;
}

#map {
  margin: 20px 0px 20px;
  padding-left: 20px;
  width: 100%;
  height: 100%;
  position: relative;
  font-style: italic;
}


              
            
!

JS

              
                n_a = 'HTML5 Geolocation supported, but location data is currently unavailable.'
url = 'https://maps.google.com/maps/api/staticmap?sensor=true&size=428x350'
lat = lng = acc = null

$msg = $('#msg')

ok = (e) ->
  at = e.coords
  lat = at.latitude;
  lng = at.longitude;
  acc = at.accuracy;
  if lat and lng
    updateDisplay()
    for name, val of { lat, lng, acc }
      localStorage[name] = val
  else
    $msg.html(n_a)

updateDisplay = ->
  at = [lat, lng] + ''
  map = "<img src='#{url}&zoom=16&center=#{at}'/>"
  map = map.link "https://maps.google.com/?q=#{at}&z=16"
  for id, val of { map, lat, lng, acc }
    $("##{id}").html(val)

fail = (err) ->
  msg = [ "There was an error while retrieving your location: #{err.message}"
        , 'The user prevented this page from retrieving a location.'
        , "The browser was unable to determine your location: #{err.message}"
        , 'The browser timed out before retrieving the location.'
        ][err.code]
  $msg.text(msg).css('color', '#D03C02')

window.reset = ->
  delete localStorage[name]  for name in ['lat', 'lng', 'acc']
  $msg.text('localStorage cleared.')

if navigator.geolocation
  do load = ->
    $msg
      .html('HTML5 Geolocation is supported in your browser.')
      .css('color', '#1ABC3C')
    if localStorage?.lat
      lat = localStorage.lat
      lng = localStorage.lng
      acc = localStorage.acc
      $msg.html('Location data retrieved from localStorage. <a id="reset" href="javascript:reset();" style="margin-left: 15px;">delete</a>')
      updateDisplay()
    else
      navigator.geolocation.getCurrentPosition ok, fail, timeout: 10e3
              
            
!
999px

Console