Lasso Soft Inc. > Home

[tsp_geocode]

Linktsp_geocode
AuthorJason Huck
CategoryUtility
Version8.x
LicensePublic Domain
Posted08 Feb 2006
Updated21 Feb 2006
More by this author...

Description

This is a quick'n'dirty tag to retrieve coordinate data using the free service at geocoder.us. Per their terms of service, it is free for non-commercial use. Returns a map containing the components of the street address along with longitude and latitude. Returns null if the address could not be found. Only works with US addresses.

Sample Usage

var('address') = '1815 Griffin Road, Dania Beach, FL  33004';
var('coordinates') = tsp_geocode($address);

if($coordinates->size);
	'Latitude: ' + $coordinates->find('latitude') + '
\n'; 'Longitude: ' + $coordinates->find('longitude') + '
\n'; 'Street: ' + $coordinates->find('street') + '
\n'; 'City: ' + $coordinates->find('city') + '
\n'; 'State: ' + $coordinates->find('state') + '
\n'; 'Zip: ' + $coordinates->find('zip') + '
\n'; /if;

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define_tag(
	'geocode',
	-namespace='tsp_',
	-required='address',
	-priority='replace',
	-description='Looks up the given address at geocoder.us.'
);
	local('url' = 'http://rpc.geocoder.us/service/csv');
	local('getparams') = array(
		'address' = #address
	);
	
	local('response') = include_url(
		#url,
		-getparams=#getparams
	);
	
	#response >> 'sorry' ? return;
	
	local('out' = map);
	
	local('fields') = array(
		'latitude',
		'longitude',
		'street',
		'city',
		'state',
		'zip'
	);
	
	iterate(#response->split(','), local('i'));
		#out->insert(#fields->get(loop_count) = (loop_count < 3 ? decimal(#i) | #i));
	/iterate;
	
	return(#out);
/define_tag;

Related Tags

Comments

14 Jun 2006, Israel Thompson

Thanks a bunch!

This Tag has come in really handy! I've managed to plug it into a database and retrieve the coordinates for multiple coordinates along with search for single coordinates and display a map with a marker and info window.

I have a question for you Jason. Are you going to create a Tag for the new Google geocoder? If so, I can't wait! When they released the new Google geocoder I realized more of my addresses were coming back as "found" rather than "not found" which is what I was getting sometimes with the one used by your tag, so I'm really interested if you are going to make a tag for the Google one! :)

Thanks,

Israel

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft