Skip to content

Instantly share code, notes, and snippets.

@RandomEtc
Forked from notlion/MapUtil.as
Created January 26, 2010 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RandomEtc/286973 to your computer and use it in GitHub Desktop.
Save RandomEtc/286973 to your computer and use it in GitHub Desktop.
Ryan's quick Yahoo geocoder in as3
package candymaps.map
{
import com.modestmaps.geo.Location;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class MapUtil
{
private static var _yahoo_api_key:String;
public static function setYahooApiKey(key:String):void
{
_yahoo_api_key = key;
}
public static function geocode(location:String, callback:Function):void
{
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, function(e:Event):void{
try{
var response:XML = new XML(loader.data);
var ns:Namespace = new Namespace("urn:yahoo:maps");
callback(new Location(
response.ns::Result.ns::Latitude,
response.ns::Result.ns::Longitude
));
}
catch(e:TypeError){
trace("Error Geocoding: Could not parse XML");
}
});
loader.load(new URLRequest(
"http://local.yahooapis.com/MapsService/V1/geocode?output=xml" +
"&appid=" + _yahoo_api_key +
"&location=" + location
));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment