What I am doing wrong? I donot geting numbers trace shows Infinity

function geolocationUpdateHandler(event: GeolocationEvent): void {
event.latitude.toString();
event.longitude.toString();
trace(lat = event.latitude);
trace(lng = event.longitude);
trace(Star.x = (((lng * Math.PI / 180) - (MinLongitude * Math.PI / 180)) /  ((MaxLongitude * Math.PI / 180) - (MinLongitude * Math.PI / 180)) / Map.width));
trace(Star.y = (((lat * Math.PI / 180) - (MinLatitude* Math.PI / 180)) / ((MaxLatitude * Math.PI / 180) - (MinLatitude * Math.PI / 180)) / Map.height));

}

var MinLongitude:int; 
MinLongitude = 25.139585;
var MaxLongitude:int; 
MaxLongitude = 25.332134;
var MaxLatitude:int; 
MaxLatitude = 57.790398;
var MinLatitude:int; 
MinLatitude = 57.693223;
有帮助吗?

解决方案

I'm sure the long/latitudes return as converted to [text] string. No need for .toString method.

Correct way to trace is example: trace("my latitude is.. " + event.location);

In your code try like this:

trace( "lat = " + event.latitude );
trace( "lng = " + event.longitude );

trace( "Star.x = " + (((lng * Math.PI / 180) - (MinLongitude... etc
trace( "Star.y = " + (((lat * Math.PI / 180) - (MinLatitude... etc

Edit:

I just realised you're casting int as the type for your four vars (var MinLongitude:int etc) but also setting them up with fractional inputs. Int's cannot be fractions or have decimal places so change those types to Number eg: (var MinLongitude:Number) etc. Hopefully now you'll get good results.

Otherwise seems there is nothing with your calculation formula. So minus infinity is strange. I did manual calculation...

Star.x = (((lng * Math.PI / 180) - (MinLongitude * Math.PI / 180)) /  ((MaxLongitude * Math.PI / 180) - (MinLongitude * Math.PI / 180)) / Map.width));

in calculator becomes: (assume Map.width = 500, Math.PI = 3.14)...

(25.33213 * 3.14 / 180) - (25.139585 * 3.14 / 180) /  (25.332134 * 3.14 / 180) - (25.139585 * 3.14 / 180) / 500

and the result 6.077202837190 etc.... so Star.x = 6.0

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top