Lat/Long Location Finder

GCI 2015

by Max B.

HTML

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/js/materialize.min.js"></script>
<div>
  <form>
  <h2>Postal Code:</h2>
    <br>
    <input type="text" id="lat" value="0">
   </form>
   <hr>
   <button type="button" id="submit" class="btn waves-effect waves-light">Locate</button>
 </div>
 <hr class="hr-dashed">
   <h3>Result</h3>
   <p id="result"></p>

CSS

body {
  text-align: center;
  background-color: #292929;
}

hr {
  margin-left: 6rem;
  margin-right: 6rem;
  border-style: solid;
  border-width: 3px;
  border-color: #00acc1;
  margin-top: 15px;
  margin-bottom: 15px;
}

.hr-dashed {
  border-style: dashed;
  border-width: 1px;
  border-color: #696969;
  margin-top: 20px;
  margin-bottom: 20px;
  margin-left: 0;
  margin-right: 0;
}

form {
  background-color: #FFCC6E;
  box-shadow: 6px 6px 2px #1F1F1F;
}

div {
  margin: 4rem;
  margin-bottom: 0px;
  margin-top: 10px;
}

p {
  color: white;
  height: 5rem;
  background-color: #353535;
}

h3 {
  color: #ee6e73;
  margin-top: 5px;
  margin-bottom: 5px;
  font-size: 2rem;
}

h2 {
  background-color: #FFB834;
  font-size: 16px;
  font-weight: bold;
  line-height: 25px;
  margin: 0;
}

input[type="text"] {
  background-color: #FFE4B2;
}

JavaScript

var long = 0;
var lat = 0;

function error (msg) {
	$("#result").text(msg);
}

function submit () {
	if (Number.isNaN(parseFloat($("#lat").val()))) { error("Postal Code must be a number!"); return; }
  
  var postal = parseFloat($("#lat").val());
  
	$.getJSON("https://nominatim.openstreetmap.org/?format=json&addressdetails=1&postalcode="+postal, function( data ) {
		$("#result").html("<b>Latitude:</b> " + data[0].lat + "<br /> <b>Longitude:</b> " + data[0].lon);
	});
}

$("#submit").click(submit);