Lasso Soft Inc. > Home

[weatherbug_getLocation]

Linkweatherbug_getLocation
AuthorShelane French
CategoryUtility
Version8.x
LicensePublic Domain
Posted01 Apr 2007
Updated01 Apr 2007
More by this author...

Description

Returns location information (city, state, country) via the WeatherBug API.
Requires a valid WeatherBug API key. This tag also requires the [xml_tree]
type.

Sample Usage

var: 'wbLocale' = weatherbug_getLocation(-key=$key, -zip=$zip);
var: 'wbCurrentCity' = $wbLocale->find('location')->find('cityname');
var: 'wbCurrentState' = $wbLocale->find('location')->find('statename');

$wbCurrentCity ', ' $wbCurrentState;

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(
	'getLocation',
	-namespace='weatherbug_',
	-required='key',
	-required='zip',
	-priority='replace',
	-description='Returns location information for the given zip code.'
);

	local('url' = 'http://' + #key + '.api.wxbug.net/getLocationsXML.aspx');
	local('getparams') = array(
		'ACode' = #key,
		'SearchString' = #zip
	);
	
	local('response') = include_url(
		#url,
		-getparams=#getparams
	);
	
	local('xmldata') = xml_tree(#response);

	local('out' = map);
	iterate(#xmldata->locations->children, local('i'));
		if(#i->name && #i->name != 'text');
				local('map' = map);
				#map->insert('value' = #i->contents);
				
				if: #i->attributes;
					iterate: #i->attributes, (local: 'attribute');
						#map->insert(#attribute->first = decode_xml(#attribute->second));
					/iterate;
				/if;
				#out->insert(#i->name = #map);
		/if;
	/iterate;
		
	return(@#out);		
/define_tag;

Related Tags

Comments

No comments

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