-
-
Save RandomEtc/286973 to your computer and use it in GitHub Desktop.
Ryan's quick Yahoo geocoder in as3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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