block by wboykinm 7326973

Mapbox Geolocation by IP

Full Screen

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title></title>
  <script src='//api.tiles.mapbox.com/mapbox.js/v1.4.0/mapbox.js'></script>
  <script src='//codeorigin.jquery.com/jquery-1.10.2.min.js'></script>
  <link href='//api.tiles.mapbox.com/mapbox.js/v1.4.0/mapbox.css' rel='stylesheet' />
  <!--[if lte IE 8]>
    <link href='//api.tiles.mapbox.com/mapbox.js/v1.4.0/mapbox.ie.css' rel='stylesheet'>
  <![endif]-->
  <style>
    body { margin:0; padding:0; }
    #map { position:absolute; top:0; bottom:0; width:100%; }
  </style>
</head>
<body>
<div id='map'></div>
<script type='text/javascript'>
  // Set default location in case the IP doesn't have one
  var lat = 40.8;
  var lon = -96.67;
  // Grab IP location from freegeoip API
  $.getJSON('//freegeoip.net/json/', function(json) {
    if (json) {
      lat = json.latitude;
      lon = json.longitude;
    }
    // Build the map
    var map = L.mapbox.map('map', 'landplanner.g7443phg').setView([lat, lon], 8);
    // Add a draggable marker at the IP location
    
    var marker = L.marker(new L.LatLng(lat, lon), {
        icon: L.icon({
          iconUrl: "//farm6.staticflickr.com/5519/10708548293_e38037720a_o.png",
          iconSize: [128, 128],
          iconAnchor: [64, 64],
          popupAnchor: [0, -64],
          className: "dot"
        }),
        draggable: true
    });

    marker.bindPopup('Am I off the map? Drag me to the right spot!');
    marker.addTo(map);
  });

</script>
</body>
</html>