Geolocation Flash App
I’ve been busy analyzing data for the last couple days, but in my down time I’ve been playing with creating a more accurate way to determine a person’s location when they take one of my experiments. In the test file, I am gathering much more info than I would in a proper experiment – anonymity is very important so most likely I’d only actually store geolocation data at the country level. IPs would never get stored unless it was a special case and the participants were notified of this.
I’m still testing this thing to see how accurate it is so, if you want, leave a comment below to let me know if it did indeed locate you properly.
This app was developed in Flash CS4 using AS3 with an embedded Google map. Geolocation data is gathered using the GeoLite module from MaxMind. I decided to use the .dat file since it is much faster than sticking all the geo data in a database.
Below is a cleaned up and simplified version of the geolocation SWF file.
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
import com.google.maps.overlays.MarkerOptions;
import com.google.maps.overlays.Marker;
import com.google.maps.styles.StrokeStyle;
import com.google.maps.styles.FillStyle;
var ip:String;
var country_short:String;
var country_long:String;
var country_name:String;
var region_short:String;
var region_long:String;
var city:String;
var latitude:Number;
var longitude:Number;
var map:Map = new Map();
function sortUID():void {
var request:URLRequest=new URLRequest("http://www.YOUR GEO PHP PAGE.php");
request.method=URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
var loader:URLLoader=new URLLoader(request);
loader.addEventListener(Event.COMPLETE, onComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
loader.dataFormat=URLLoaderDataFormat.VARIABLES;
loader.load(request);
txt.htmlText="Gathering Data...";
function onComplete(event:Event):void {
loaderAnim.visible=false;
loaderAnim.gotoAndStop(61);
ip=event.target.data.ip;
country_short=event.target.data.country_short;
country_long=event.target.data.country_long;
country_name=event.target.data.country_name;
region_short=event.target.data.region_short;
region_long=event.target.data.region_long;
city=event.target.data.city;
latitude=event.target.data.latitude;
longitude=event.target.data.longitude;
txt.htmlText="IP: "+ip;
txt.appendText("\n"+country_short);
txt.appendText("\n"+country_long);
txt.appendText("\n"+country_name);
txt.appendText("\n"+region_short);
txt.appendText("\n"+region_long);
txt.appendText("\n"+city);
txt.appendText("\nlatitude: "+latitude);
txt.appendText("\nlongitude: "+longitude);
showMap();
}
function onIOError(event:IOErrorEvent):void {
trace("Error loading URL.");
}
}
sortUID();
function showMap() {
map.key="ENTER YOUR GOOGLE MAP KEY";
map.setSize(new Point(550, 680));
map.buttonMode=true;
map.addEventListener(MapEvent.MAP_READY, onMapReady);
this.addChild(map);
function onMapReady(event:Event):void {
map.setCenter(new LatLng(latitude,longitude), 14, MapType.NORMAL_MAP_TYPE);
var marker:Marker = new Marker(
new LatLng(latitude,longitude),
new MarkerOptions({
strokeStyle: new StrokeStyle({color: 0x666666}),
fillStyle: new FillStyle({color: 0xFF00FF, alpha: 0.8}),
radius: 12,
hasShadow: true
}));
map.addOverlay(marker);
}
}

The work on this page is licensed under a
Creative Commons Attribution-ShareAlike 3.0 Unported License.
One Comment
One Trackback
-
[...] An example flash app is http://www.playgraph.com/2009/bits/geolocation-flash-app [...]
Adam
66 days ago
Love it. Worked.