JoachimPetersen
asked on
Flex Mobile: Get Gps Coordinates
Hello
I am trying to make an app that will use the mobile's GPS sensor, the problem is that I wan't to make it as a function where it return the coordinate, how can I do this?
I have tried this:
Gps flex code example
How can I change this so I will just have a function where it will return the current gps location insted of having the UpdateHandler do it?
I am trying to make an app that will use the mobile's GPS sensor, the problem is that I wan't to make it as a function where it return the coordinate, how can I do this?
I have tried this:
Gps flex code example
private function SetGeoLocation:void
{
if (Geolocation.isSupported)
{
geo = new Geolocation();
geo.setRequestedUpdateInterval(100);
geo.addEventListener(GeolocationEvent.UPDATE, geolocationUpdateHandler);
}
else
{
log.text = "No geolocation support.";
log.setTextFormat(format)
}
}
private function geolocationUpdateHandler(event:GeolocationEvent):void
{
log.text = "lat:" + event.latitude.toString() + " - ";
log.appendText("long:" + event.longitude.toString() + "° - ");
log.appendText("Accuracy:" + event.horizontalAccuracy.toString() + " m");
log.setTextFormat(format)
}
How can I change this so I will just have a function where it will return the current gps location insted of having the UpdateHandler do it?
ASKER
The problem is having the gps to run every 100 mill sec, it will be power consuming, I need to read the gps coordinates from 3 different functions, I essentially neeed the gps result different times(not the same timer.), is this the only was as I would like to have only the newest gps results.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, just one last question: why can't I access the specefic result like only the latitude:
getGPSCoOrdinates().latitu de? I am new to as3 so is there anything special you have to do to get the value for latitude from the array?
getGPSCoOrdinates().latitu
The call returns an object, you should be able to access the individual properties of the object to get what you need
to answer your last question (I haven't tested this)
(GpsLocator.getInstance(). getGPSCoOr dinates()) .latitude
Regards
Gary
var lastGpsCoord:Object = GpsLocator.getInstance().getGPSCoOrdinates();
var lat:int = lastGpsCoord.latitude;
var cp:Object = GpsLocator.getInstance().getGPSCoOrdinates();
log.text = "lat:" + cp.latitude.toString() + " - ";
log.appendText("long:" + cp.longitude.toString() + "° - ");
log.appendText("Accuracy:" + cp.horizontalAccuracy.toString() + " m");
log.setTextFormat(format)
to answer your last question (I haven't tested this)
(GpsLocator.getInstance().
Regards
Gary
Do you need any more help with this?
Regards
Gary
Regards
Gary
You are asking the app to update the gps coordinates every 100 milliseconds, if you just want a function that returns the GPS coordinates every time you call it you just need to store the GPS coordinates in the update handler and then return those co-ordinates in your new function
// create a private class variable to store the last known GPS coordinate in
private var last_gps_coord:Object;
// this event handler will get called every 100ms, update the private class variable when it is called with the last location data
private function geolocationUpdateHandler(e
{
this.last_gps_coord = { latitude:event.latitude, longitude:event.longitude,
}
// call this function when you want the lastest coordinate
public function getGPSCoOrdinates():Object
{
return this.last_gps_coord;
}
eg.
var cp:Object = yourClassInstance.getGPSCo
log.text = "lat:" + cp.latitude.toString() + " - ";
log.appendText("long:" + cp.longitude.toString() + "° - ");
log.appendText("Accuracy:"
log.setTextFormat(format)
Regards
Gary