Converting UTM Coordinates to Lat/Long
I am using a sensor hardware device to send UTM Coordinate Grids into Unity and trying to convert into Lat/Long to use with Google maps for my AR project. I have the conversion code cleaned up but im getting an error when I play it. Here is my code and error, Im sure Im missing something simple. Thank you.
Error: NotImplementedException: The requested feature is not implemented.
using UnityEngine;
using System.Collections;
using System;
using System.Linq;
public class NewBehaviourScript : MonoBehaviour {
public double utmEast; //483296.5
public double utmNorth; //3615927.1
public string utmZone;
private double utmX;
private double utmY;
void Start()
{
ToLatLon();
}
void Update () {
utmEast = utmX;
utmNorth = utmY;
}
private void ToLatLon()
{
throw new NotImplementedException();
}
public static void ToLatLon(double utmX, double utmY, string utmZone, out double latitude, out double longitude)
{
bool isNorthHemisphere = utmZone.Last() >= 'N';
var diflat = -0.00066286966871111111111111111111111111;
var diflon = -0.0003868060578;
var zone = int.Parse(utmZone.Remove(utmZone.Length - 1));
var c_sa = 6378137.000000;
var c_sb = 6356752.314245;
var e2 = Math.Pow((Math.Pow(c_sa, 2) - Math.Pow(c_sb, 2)), 0.5) / c_sb;
var e2cuadrada = Math.Pow(e2, 2);
var c = Math.Pow(c_sa, 2) / c_sb;
var x = utmX - 500000;
var y = isNorthHemisphere ? utmY : utmY - 10000000;
var s = ((zone * 6.0) - 183.0);
var lat = y / (c_sa * 0.9996);
var v = (c / Math.Pow(1 + (e2cuadrada * Math.Pow(Math.Cos(lat), 2)), 0.5)) * 0.9996;
var a = x / v;
var a1 = Math.Sin(2 * lat);
var a2 = a1 * Math.Pow((Math.Cos(lat)), 2);
var j2 = lat + (a1 / 2.0);
var j4 = ((3 * j2) + a2) / 4.0;
var j6 = ((5 * j4) + Math.Pow(a2 * (Math.Cos(lat)), 2)) / 3.0;
var alfa = (3.0 / 4.0) * e2cuadrada;
var beta = (5.0 / 3.0) * Math.Pow(alfa, 2);
var gama = (35.0 / 27.0) * Math.Pow(alfa, 3);
var bm = 0.9996 * c * (lat - alfa * j2 + beta * j4 - gama * j6);
var b = (y - bm) / v;
var epsi = ((e2cuadrada * Math.Pow(a, 2)) / 2.0) * Math.Pow((Math.Cos(lat)), 2);
var eps = a * (1 - (epsi / 3.0));
var nab = (b * (1 - epsi)) + lat;
var senoheps = (Math.Exp(eps) - Math.Exp(-eps)) / 2.0;
var delt = Math.Atan(senoheps / (Math.Cos(nab)));
var tao = Math.Atan(Math.Cos(delt) * Math.Tan(nab));
longitude = ((delt * (180.0 / Math.PI)) + s) + diflon;
latitude = ((lat + (1 + e2cuadrada * Math.Pow(Math.Cos(lat), 2) - (3.0 / 2.0) * e2cuadrada * Math.Sin(lat) * Math.Cos(lat) * (tao - lat)) * (tao - lat)) * (180.0 / Math.PI)) + diflat;
print(latitude);
print(longitude);
}
}
Answer by Statement · Oct 24, 2015 at 10:40 PM
NotImplementedException: The requested feature is not implemented.
void Start()
{
ToLatLon();
}
void ToLatLon()
{
throw new NotImplementedException(); // "The requested feature is not implemented."
}
Do I need to say more?
So i made some changes and took that out but I put that in there from something I read on another forum that solved the error Im getting now. It seems so simple, Im just trying to run the ToLatLon() function in the Update function and keep looking to give me updated LatLong coordinates, how am I messing this up, I feel retarded. Im no expert but this also isnt day 1 lol.
using UnityEngine;
using System.Collections;
using System;
using System.Linq;
public class NewBehaviourScript : $$anonymous$$onoBehaviour {
public double utmEast = 483296.5;
public double utmNorth = 3615927.1;
public string utmZone;
private double utmX;
private double utmY;
void Start()
{
// ToLatLon();
}
void Update () {
utmEast = utmX;
utmNorth = utmY;
ToLatLon();
}
/* private void ToLatLon()
{
throw new NotImplementedException();
}*/
void ToLatLon(double utmX, double utmY, string utmZone, out double latitude, out double longitude)
{
void Update () {
ToLatLon();
}
void ToLatLon(double utmX, double utmY, string utmZone, out double latitude, out double longitude)
Well.. You need to pass arguments to ToLatLon. It needs to know utmX, utmY, utmZone, pass back a latiude and longitude...
double utmX = 0;
double utmY = 0;
string utmZone = "I have no idea";
double latitude, longitude;
ToLatLon(utmX, utmY, utmZone, out latitude, out longitude);
print ("latitude: " + latitude);
print ("longitue: " + longitude);
Answer by Surfninja · Oct 26, 2015 at 12:11 PM
I made the changes and received a whole slew of errors, any thoughts and what i did wrong. print("latitude: " + latitude); print("longitue: " + longitude);
is at the end of :
void ToLatLon(utmX, utmY, utmZone, out latitude, out longitude)
public class NewBehaviourScript : MonoBehaviour {
//public double utmEast = 483296.5;
//public double utmNorth = 3615927.1;
string utmZone = N;
double utmX = 483296.5;
double utmY = 3615927.1;
double latitude, longitude;
void Update () {
ToLatLon();
}
void ToLatLon(utmX, utmY, utmZone, out latitude, out longitude)
{
bool isNorthHemisphere = utmZone.Last() >= 'N';
etc, etc....
ToLatLon();
You are still not passing arguments to the function.
ToLatLon(utmX, utmY, utmZone, out latitude, out longitude);
But you got other problems...
string utmZone = N;
is not a string. Perhaps you meant "N"?
utmZone.Last() >= 'N'
should probably be
utmZone.Last() == 'N'
Your right, that makes sense. I changed some stuff up and got it down to 9 errors lol. *Im missing an assembly identifier referenced to void(latitude, longitude) *The type or namespace name Lat/ Lon could not be found. *Cannot convert char to string.....I thought string was variables formed by letters and not numbers? *Cannot convert out double to out Lat/Lon *The out parameter must be assigned before control leaves the current method
string utmZone = 'N';
double utmX = 483296.5;
double utmY = 3615927.1;
double latitude, longitude;
void Update () {
ToLatLon(utmX, utmY, utmZone, out latitude, out longitude);
}
void ToLatLon(double utmX,double utmY,string utmZone, out latitude, out longitude)
{
bool isNorthHemisphere = utmZone.Last() == 'N'
;
Your answer
Follow this Question
Related Questions
Doing a multiplayer location based game 0 Answers
How Do I Get An Object At Given Position? 0 Answers
Instantiated objects can't convert to GameObjects 0 Answers
Player spawn in the center of the world 2 Answers