Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Surfninja · Oct 24, 2015 at 05:09 PM · locationconversiongrids

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);
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Surfninja · Oct 25, 2015 at 10:37 AM 0
Share

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)
     {
avatar image Statement Surfninja · Oct 25, 2015 at 01:24 PM 0
Share
 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);
avatar image
0

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....



Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Oct 26, 2015 at 12:58 PM 0
Share
 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'
avatar image Surfninja · Oct 26, 2015 at 02:30 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

31 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Doing a multiplayer location based game 0 Answers

How Do I Get An Object At Given Position? 0 Answers

Assets/Prefab/Tree.cs(63,9): error CS1502: The best overloaded method match for `UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Vector3, UnityEngine.Quaternion)' has some invalid arguments how to solve it?? 1 Answer

Instantiated objects can't convert to GameObjects 0 Answers

Player spawn in the center of the world 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges