Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 91 lines (79 sloc) 2.702 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
<!DOCTYPE html>
<html>
<head>
<title>Single-Line Address Parsing</title>
<meta charset="UTF-8">
<script src="content/js/jquery.js"></script>
<script>
/**
Single-Line Address Parsing (SLAP) Demo
By SmartyStreets
LiveAddress API: http://smartystreets.com/products/liveaddress-api
Demo at JsFiddle: http://jsfiddle.net/smartystreets/dw2N5/
Attempts to parse a single-line (freeform)
address and split into its components. When
the whole address is passed into the
"street" field, LiveAddress will automatically
attempt to parse the pieces of the address
and will usually be able to return valid results.
*/

var js_api_token = 'PUT YOUR HTML IDENTIFIER HERE';

// The base URL of the request (JSONP will be appended later)
var base = 'https://api.smartystreets.com/street-address/?auth-token=' + js_api_token;


function suppress(event) {
// Used to prevent form submission
if (!event) return false;
if (event.preventDefault) event.preventDefault();
if (event.stopPropagation) event.stopPropagation();
if (event.cancelBubble) event.cancelBubble = true;
return false;
}

$(function() {
$('#singleLineDemo').submit(function(event) {
var addr = {
street: $('#addr').val()
};

$.ajax({
url: base,
data: addr,
dataType: 'jsonp',
success: function(response) {
if (response.length > 0) {
$('#results').html(JSON.stringify(response, null, ' '));
$('#address').html(response[0].delivery_line_1 + "<br>" + response[0].last_line);
}
else {
$('#address').html('No valid matches found. Please make sure a city & state OR a zip code was provided with the street address.');
$('#results').empty();
}
}
});

return suppress(event);
});
});
</script>
<style>
body { width: 960px; margin: 50px auto; }
input { font-size: 16px; padding: 5px; }
input[type=text] { width: 75%; }
form { margin-bottom: 2em; }
#address { font: 18px/1.5em sans-serif; }
#results {
margin-top: 3em;
background: #CCC;
text-shadow: 0px 1px 0px white;
white-space: pre;
padding: 10px;
font: 12px/1.5em Monaco, 'Lucida Grande', 'Courier New', serif;
}
</style>
</head>
<body>
<form id="singleLineDemo">
<input type="text" id="addr">
<input type="submit" value="Perform SLAP">
</form>


<div id="address"></div>
<div id="results"></div>
</body>
</html>
Something went wrong with that request. Please try again.