I am currently in the process with making an app that shall show the loaction retrived from the GPS sensor and displying the position in UTM format (WGS83 datum).
Is there a way to get the location info from the GPS as UTM?
On Tuesday, October 9, 2012 12:40:16 PM UTC+2, Karl Kristian Markman wrote:
> Hi
> I am currently in the process with making an app that shall show the > loaction retrived from the GPS sensor and displying the position in UTM > format (WGS83 datum).
> Is there a way to get the location info from the GPS as UTM?
I hav found the forumla but Im not sure how to use the formula in code. I mean do I just put the numbers and calculations in or do I need a special syntax for things like sinus and cosinus?
On Tuesday, October 9, 2012 2:17:12 PM UTC+2, Rudolf Hornig wrote:
> No. Location is provides as lat/lon in WGS84. You have to convert that to > UTM.
> On Tuesday, October 9, 2012 12:40:16 PM UTC+2, Karl Kristian Markman wrote:
>> Hi
>> I am currently in the process with making an app that shall show the >> loaction retrived from the GPS sensor and displying the position in UTM >> format (WGS83 datum).
>> Is there a way to get the location info from the GPS as UTM?
On Tuesday, October 9, 2012 9:16:20 PM UTC+2, Karl Kristian Markman wrote:
> I figured as much.
> I hav found the forumla but Im not sure how to use the formula in code. I > mean do I just put the numbers and calculations in or do I need a special > syntax for things like sinus and cosinus?
> On Tuesday, October 9, 2012 2:17:12 PM UTC+2, Rudolf Hornig wrote:
>> No. Location is provides as lat/lon in WGS84. You have to convert that to >> UTM.
>> On Tuesday, October 9, 2012 12:40:16 PM UTC+2, Karl Kristian Markman >> wrote:
>>> Hi
>>> I am currently in the process with making an app that shall show the >>> loaction retrived from the GPS sensor and displying the position in UTM >>> format (WGS83 datum).
>>> Is there a way to get the location info from the GPS as UTM?
> Can someone pleas tell me how to get numbers in power ?
> Like this (syntax used in Excel): 45^(3/2) ?
> On Tuesday, October 9, 2012 9:16:20 PM UTC+2, Karl Kristian Markman wrote:
>> I figured as much.
>> I hav found the forumla but Im not sure how to use the formula in code. I >> mean do I just put the numbers and calculations in or do I need a special >> syntax for things like sinus and cosinus?
>> On Tuesday, October 9, 2012 2:17:12 PM UTC+2, Rudolf Hornig wrote:
>>> No. Location is provides as lat/lon in WGS84. You have to convert that >>> to UTM.
>>> On Tuesday, October 9, 2012 12:40:16 PM UTC+2, Karl Kristian Markman >>> wrote:
>>>> Hi
>>>> I am currently in the process with making an app that shall show the >>>> loaction retrived from the GPS sensor and displying the position in UTM >>>> format (WGS83 datum).
>>>> Is there a way to get the location info from the GPS as UTM?
> I hav found the forumla but Im not sure how to use the formula in code. I > mean do I just put the numbers and calculations in or do I need a special > syntax for things like sinus and cosinus?
On Thursday, October 11, 2012 2:12:50 AM UTC+2, Lew wrote:
> Karl Kristian Markman wrote:
>> I figured as much.
>> I hav found the forumla but Im not sure how to use the formula in code. I >> mean do I just put the numbers and calculations in or do I need a special >> syntax for things like sinus and cosinus?
OMFG, dude! You are just all over the place with this. Variables out of nowhere, terse obscure names, varying idioms for the same kinds of calculations, utter lack of comments or whitespace, except for the exorbitant indentation, variable names that imply different values, and the one and only comment you include tells nothing except for a falsehood that isn't relevant anyway, and would have been self-explanatory in code if the variables had been constants.
I gather this code is meant neither to be re-used, shared nor maintained.
> OMFG, dude! You are just all over the place with this. Variables out of > nowhere, > terse obscure names, varying idioms for the same kinds of calculations, > utter > lack of comments or whitespace, except for the exorbitant indentation, > variable names > that imply different values, and the one and only comment you include > tells nothing > except for a falsehood that isn't relevant anyway, and would have been > self-explanatory > in code if the variables had been constants.
> I gather this code is meant neither to be re-used, shared nor maintained.
> -- > Lew
Have you see the formulas for converting Lew?
Yes i agree I have not been good with comments. If its any constalation I will update the code mow that its working....
public void onLocationChanged(Location location) {
lat = Math.toRadians(location.getLatitude()); // Latitude in radians lng = Math.toRadians(location.getLongitude()); // Longitude in radians lngdeg = location.getLongitude(); // Latitude in "normal" form. dd.dd convert();
public void convert(){ // konverter fra Lat /Long til UTM (WGS84 / NAD84) public final double knu = 0.9996; // scale along central meridian of zone public final double a = 6378137; //Equatorial radius in meters public final double b = 6356752.3142; // Polar radius in meters
e = Math.sqrt(1-(b*b)/(a*a)); // e = the eccenticity of the earth's elliptical cross-section e2 = e*e/(1-(e*e)); // The quantile e' only occurs in even powers n =(a-b)/(a+b); zone = (int) (31 + (lngdeg/6)); // Calculating UTM zone using Longetude in dd.dd form as supplied by the GPS double pi = 6* zone -183; // Central meridian of zone double pii = (lngdeg-pi)*Math.PI/180; //Differance between Longitude and central meridian of zone rho = a * (1-e*e)/ Math.pow((1-(e*e) * (Math.sin(lat)*( Math.sin(lat)))), (3/2)); // The radius of the curvature of the earth in meridian plane nu = a/(Math.pow((1-(e*e *(Math.sin(lat))*(Math.sin(lat)))), (1/2))); //The radius of the curvature of the earth perpendicular to the meridian plane /* * A0 - E0 is used for calclulating the Meridinol arc through the given point (lat long) * The distance from the earth's surface form the equator. All angles are in radians * */ A0 = a*(1 - n + (5/4)*(Math.pow(n,2) - Math.pow(n,3)) + (81/64)*(Math.pow(n,4) - Math.pow(n,5))); B0 =(3*a*n/2)*(1 - n - (7*n*n/8)*(1-n) + (55/64)*(Math.pow(n, 4)-Math.pow(n, 5))); C0 =(15*a*n*n/16)*(1 - n +(3*n*n/4)*(1-n)); D0 =(35*a*Math.pow(n, 3)/48)*(1 - n + 11*n*n/16); E0 =(315*a*Math.pow(n,4)/51)*(1-n); // Calculation of the Meridional Arc S = A0* lat - B0 * Math.sin(2*lat) + C0 * Math.sin(4*lat) - D0 * Math.sin(6*lat) + E0 * Math.sin(8*lat); /* * y = northing = Ki+ Kiip^2 + Kiip^4 * * */ double Ki = S * knu; double Kii = knu * nu *Math.sin(lat)*Math.cos(lat)/2; double Kiii = (knu * nu *Math.sin(lat)*Math.pow(Math.cos(lat),3)/24)*(5-Math.pow(Math.tan(lat),2)+9 *Math.pow(e2,2)*Math.pow(Math.cos(lat),2)+4*Math.pow(e2 ,2)*Math.pow(Math.cos(lat),4)); /* * x = easting = Kivpii + Kvpii^3 + */ double Kiv = knu * nu *Math.cos(lat); double Kv = knu * Math.pow(Math.cos(lat),3)*(nu/6)*(1-Math.pow(Math.tan(lat),2)+e2*Math.pow(M ath.cos(lat),2));
double UTMni = (Ki+Kii*Math.pow(pii, 2)+ Kiii * Math.pow(pii,4));// Northing double UTMei = 500000 + (Kiv*pii + Kv * Math.pow(pii, 3)); //Easting is relative to the central meridain. Forconvetional UTM Easting add 5000000 meters to x UTMn = (int) UTMni; // Northing, rounded to closest integer UTMe = (int) UTMei; // Easting, rounded to closest integer }
Sorry for the TAB usage but I just copy/past from eclipse..
I have one more problem here. The conversion sort of works but I miss the target by about 200 meters West. I have figured it out to bee this line that screws everything up.:
nu = a/(Math.pow((1-(e*e* Math.sin(lat)*Math.sin(lat))), (1/2));
As it is written in plain language:
nu = a/(1-e^2sin(lat)^2)^1/2
When I enter this in to excel I get 6394567 and from my app I get 6378922. This follows through on every calculation done after.
I saw one place (in Java code though) where they used Math.pow(Math.sin(lat),(1/2.0)) for setting odd powers.
On Friday, October 19, 2012 1:32:23 PM UTC+2, Karl Kristian Markman wrote:
> Sorry for the TAB usage but I just copy/past from eclipse..
> I have one more problem here. The conversion sort of works but I miss the > target by about 200 meters West. I have figured it out to bee this line > that screws everything up.:
> nu = a/(Math.pow((1-(e*e* Math.sin(lat)*Math.sin(lat))), (1/2));
> As it is written in plain language:
> nu = a/(1-e^2sin(lat)^2)^1/2
> When I enter this in to excel I get 6394567 and from my app I get 6378922. > This follows through on every calculation done after.
> I saw one place (in Java code though) where they used > Math.pow(Math.sin(lat),(1/2.0)) for setting odd powers.
To answer my own question. IT works, hallelujah.
For some reason (currently unknown to me) the java.lang.math needs to have decimal point in order to "understand" fractional powers.
Someone will probably tell me why in a sarcastic way. B)
It's not java.lang.math that needs to have the decimal point but Java the language: 1/2 is integer 1 divided by integer 2 result integer 0 1.0/2.0 is double 1.0 divided by double 2.0 result double 0.5
On Friday, October 19, 2012 1:31:57 PM UTC+1, Karl Kristian Markman wrote:
> On Friday, October 19, 2012 1:32:23 PM UTC+2, Karl Kristian Markman wrote:
>> Sorry for the TAB usage but I just copy/past from eclipse..
>> I have one more problem here. The conversion sort of works but I miss the >> target by about 200 meters West. I have figured it out to bee this line >> that screws everything up.:
>> nu = a/(Math.pow((1-(e*e* Math.sin(lat)*Math.sin(lat))), (1/2));
>> As it is written in plain language:
>> nu = a/(1-e^2sin(lat)^2)^1/2
>> When I enter this in to excel I get 6394567 and from my app I get >> 6378922. This follows through on every calculation done after.
>> I saw one place (in Java code though) where they used >> Math.pow(Math.sin(lat),(1/2.0)) for setting odd powers.
> To answer my own question. IT works, hallelujah.
> For some reason (currently unknown to me) the java.lang.math needs to > have decimal point in order to "understand" fractional powers.
> Someone will probably tell me why in a sarcastic way. B)