0

How can I get the exact Latitude and Longitude? I only get whole numbers. From my understanding, in order to get down to the meter I need to get down to 5 decimal places. I have tried the horizontal and vertical accuracy but they don't match my phones GPS reading. How can I get an exact GPS reading with Geolocation API, Down to the meter? here is my code

var my_geo:Geolocation = new Geolocation();
my_geo.setRequestedUpdateInterval(2000);                
my_geo.addEventListener(GeolocationEvent.UPDATE, onGeoUpdate);

function onGeoUpdate(e:GeolocationEvent):void
{
    gpsLat1 = (e.latitude);
    gpsLon1 = (e.longitude);
    gpsHeading = (e.heading);
    gpsHorAcc = (e.horizontalAccuracy);
    gpsVerAcc = (e.verticalAccuracy);
    gpsCheck = 2;
my_txt.text = "My Latitude is "+ gpsLat1 + " and my Longitude is "+ gpsLon1 + " Bearing is " + gpsHeading+ " HorAcc "+ gpsHorAcc+ " VertAcc "+gpsVerAcc;

}
Catttdaddy
  • 75
  • 1
  • 1
  • 7
  • 1
    Post your code. What have you tried? – nedaRM Sep 03 '13 at 03:28
  • I edited my original post to include my code. – Catttdaddy Sep 03 '13 at 19:27
  • Come on, It can not be that the Geolocation API does not give more precise GPS reading than this. If so its useless... – Catttdaddy Sep 04 '13 at 02:34
  • This is not the correct API to use to get your current location. You should be using LocationManager. Have a look at this post which has few links to good tutorials. http://stackoverflow.com/a/8543819/2045570 – nedaRM Sep 04 '13 at 03:40
  • This API is not the correct one for Adobe AIR? Is LocationManager for AIR or Java? From my understanding it is for Java.. This question is for Actionscript 3 Adobe AIR API... Maybe you just cant get a precise GPS reading with AIR. Im not getting any answers... – Catttdaddy Sep 04 '13 at 04:01
  • No, you are using the correct API. It is not uncommon for StackOverflow users to answer AIR mobile questions as if they were native questions, either because they do not know what AIR is or just see that it showed up in the Android tag and assume. Either way, you are using the correct API here and I believe the Geolocation API actually uses the LocationManager API to function. – Josh Sep 04 '13 at 16:45

2 Answers2

0

Try this:

function onGeoUpdate(e:GeolocationEvent):void
{
    gpsLat1 = (e.latitude.toString());
    gpsLon1 = (e.longitude.toString());
    gpsHeading = (e.heading.toString());
    gpsHorAcc = (e.horizontalAccuracy.toString());
    gpsVerAcc = (e.verticalAccuracy.toString());
    gpsCheck = 2;
    my_txt.text = "My Latitude is "+ gpsLat1 + " and my Longitude is "+ gpsLon1 + " Bearing is " + gpsHeading+ " HorAcc "+ gpsHorAcc+ " VertAcc "+gpsVerAcc;

}
nedaRM
  • 1,837
  • 1
  • 14
  • 28
  • If his variables are of type `Number`, `uint`, or `int`, this will return "My latitude is NaN", as you cannot save a string to a number object – Josh Sep 04 '13 at 16:43
0

Make sure your variables (gpsLat1, gpsLon1, gpsHeading, etc.) are of type Number and not a uint or int. Unsigned Integers and Integers only allow for whole numbers, whereas Number is the equivalent of float in most other languages (and allows for incredibly larger values, as well). If you save a decimal to an integer, it is rounded off/floored (I can't remember which), which sounds exactly like the problem you are having.

Alternatively, the API is restricted by the hardware you are testing on. If the hardware only returns a certain value for GPS coordinates, AIR cannot be any more precise. Odds are this is not the issue since a whole lat long point can be miles and miles in distance, meaning any device with that inaccurate of a GPS chip is absolutely useless.

Josh
  • 8,079
  • 3
  • 24
  • 49
  • The problem isnt that the information is not displaying. Its that it is not precise enough.I only get Latitude XX, Longitude -XX. I cant use that information in any meaningful way. One degree of latitude is like 68 miles... – Catttdaddy Sep 05 '13 at 05:38
  • @Catttdaddy Which is why I suggested you verify you are saving them to a Number variable and not a uint or int. If you save them to a uint or int, they will get cut off and not be precise because a uint or int cannot have decimal points. – Josh Sep 05 '13 at 10:02
  • Oh snap! I didnt think about that! They are int. I am at work now but I will try this when I get home! – Catttdaddy Sep 05 '13 at 20:24