views:

2050

answers:

3

I making a web app in Flex using global coordinates

I get the coordinates as strings from a web service then I do something like this:

latStr:String = "28.7242100786401";
longStr:String = "-106.12635420984";

var cLat:Number = new Number(latStr);
var cLong:Number = new Number(longStr);

This works PERFECT on IE and chrome, from the web server and when debugging locally, but Firefox just works when debugging locally and not from the web server, in the web server cLat and cLong return "NaN".

check it out yourself, it should pop up an alert when you click on a result: http://mundobuk.com/prueba/mapa/main.html?buscar=oxxo

so I tried using parseFloat(), but it rounds cLat to 28 and cLong to -106 :(

Then I tried separating the decimals form integers, like from my example 28 and 7242100786401 then divide 7242100786401/10000000000000 = 0.7242100786401

having 2 numbers 28 and 0.7242100786401 I add them up

28 + 0.7242100786401 = 28.7242100786401

here is in code form:

var latArr:Array = latStr.split(".");
var longArr:Array = longStr.split(".");


var latDivStr:String = "1";
for (var i:int= 0; i< latArr[1].length; i++){
latDivStr += "0";
}

var longDivStr:String = "1";
for (var j:int = 0; j< longArr[1].length; j++){
longDivStr += "0";
}
var cLat:Number = parseFloat(latArr[0]) + arseFloat(latArr[1])/parseFloat(latDivStr);
var cLong:Number = parseFloat(longArr[0]) - parseFloat(longArr[1])/parseFloat(longDivStr);

again, this way works great everywhere, just not in firefox in the web server >_>

anyone have any ideas? im going crazy whit this @_@

+1  A: 

I have never hear of such an error as The Flash run-time is supposed to make the different browsers and OS's interpret the SWF the same way. I will say that I don't believe you should be using "new" in-front of your Number casting.

latStr:String = "28.7242100786401";
longStr:String = "-106.12635420984";

var cLat:Number = new Number(latStr);
var cLong:Number = new Number(longStr);

This should be:

var cLat:Number = Number(latStr); //Number is right because its a Floating Point, but remove new.
var cLong:Number = Number(longStr); //Number is right because its a Floating Point, but remove new.

I tested the using the following and saw no rounding take place.

var latStr:String = "28.7242100786401"; var longStr:String = "-106.12635420984";

trace(parseFloat(latStr)); //Outputs:  "28.7242100786401";
trace(parseFloat(longStr)); //Outputs:  "-106.12635420984";

trace(Number(latStr)); //Outputs:  "28.7242100786401";
trace(Number(longStr)); //Outputs:  "-106.12635420984";

I do not see why you require this workaround. Also I use firefox as my main browser and your site seems to be working just fine.

Cheers,
Brian Hodge blog.hodgedev.com hodgedev.com

Brian Hodge
Hi thanks for the reply.it doesn't work in any computer I have tested it in, all with different types of flash player (9, 10, debugg and non debugg)
sergiogx
Can you please explain what I am looking for in the link to your page. Perhaps a screen shot showing the error? I see no such rounding as you have indicated.
Brian Hodge
using a sniffer, I see that the following fails - http://mundobuk.com/prueba/mapa/assets/ico/nullIs this what you mean?
Brian Hodge
hey, thanks for helping, look at this image http://mundobuk.com/prueba/mapa/scrshot.jpg this is what I see on every computer
sergiogx
But using IE and Chrome everything works perfect, you see the correct value instead of NaN
sergiogx
A: 

I finally found out why its not working, for some reason in firefox instead of reading a dot (.) it reads a comma (,) from the web service (done in vb.net)

locally it reads it as a dot too, not online, so I suppose it has to do something with my IIS server O_o

hope this helps someone out there...

sergiogx
+1  A: 

Comma is the separator for many European countries, so it's most likely the regional configuration on either the server or the client.

Richard Szalay