LocationWEB Plugin

Getting Started with the Javascript API

This document should help you get started with the new LocationWEB Javascript API.

Get started in 6 lines of code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>LocationWEB Javascript API</title>
<script type="text/javascript" src="http://locationweb.mobi/javascript/locationweb.js"></script>
<script type="text/javascript">
function load()
{
  var geo = LocationWEB();

  if (geo) {
    geo.onSuccess = function(location) {alert(location.latitude+', '+location.longitude)}
    geo.onFailure = function(error) {alert(error)}
    geo.requestLocation(true,geo.NO_STREET_ADDRESS_LOOKUP);
  }
}
</script>
</head>
<body onLoad="load();">
<h1>Simple LocationWEB Javascript API Example</h1>
</body>
</html>

Here you see a simple example of how to implement the API in only 6 simple lines. Now you will probably want to do some more intelligent error handling and do something a little more interesting with the user's location, but as you can see its easy to integrate the new API.

Reference

LocationWEB.requestLocation(latlon_lookup, address_lookup )

This method initiates the scan and the actual location request. It has two parameters that define what information you want to request from the user.

LocationWEB.onSuccess( object location )

If the call to the server executes successfully, this callback function will be executed and passed a location object. The location object could have the folloing attributes based on the paramter used during the requestLocation() call:

latitude A floating number. Example: 42.350827
longitude A floating number. Example: -71.049465
house_number The house number of the street address. Example: 332 in "332 Congress St"
street The name of the street. Example: Congress St in "332 Congress St"
city The name of the city: Example: Boston
region Internationalized. In most countries this maps to a State name, Province name or the equivalent. Example: Massachusetts or Ontario
region_code Internationalized. In most countries this maps to a State code, Province code or the equivalent. Example: MA or ON
postal_code In countries that support postal codes this field will be populated. Example: 02210 or A9A A9A
country The name of the country. Example: United States
country_code The character code representing the country: Example: US

LocationWEB.onFailure( int error )

If the request to the server fails this callback function will be executed and passed an error code. A request could fail for a number of reasons, either client-side or server side. The error code will denote what type of error occurred. The following error codes are possible: