using System.Collections; using System.Collections.Generic; using UnityEngine; public class CoordinateConverter { // 将经纬度转换为Unity坐标 public static Vector3 GeoToUnity(double longitude, double latitude) { float x = (float)(96151.617 * longitude - 10938527.4823); float z = (float)(111468.3949 * latitude - 3339986.2697); return new Vector3(x, 0, z); } // 将Unity坐标转换为经纬度 public static (double Longitude, double Latitude) UnityToGeo(Vector3 unityCoord) { double longitude = (unityCoord.x + 10938527.4823)/ 96151.617; double latitude = (unityCoord.z + 3339986.2697)/ 111468.3949; // 这里我们忽略了截距,因为我们假设Unity坐标的原点对应于经纬度的截距 // 如果需要考虑截距,可以在这里添加相应的计算 return (longitude, latitude); } public static Vector3 GeoToUGUI(double longitude, double latitude) { float x = (float)(355.53f * longitude - 40339.8622f); float y = (float)(409.37f * latitude - 12420.05f); return new Vector3(x, y, 0); } public static Vector3 GeoToUGUISmall(double longitude,double latitude) { float x = (float)(-48.538f * longitude + 5509.732f); float y = (float)(-50.542f * latitude + 1506.543f); return new Vector3(x, 0, y); } public static (double Latitude, double Longitude) UGUISmallToGeo(Vector3 uiCoord) { double latitude = (uiCoord.x + 170020.42) / 1494.66; double longitude = (uiCoord.y + 44250.98) / 1471.72; // 这里我们忽略了截距,因为我们假设Unity坐标的原点对应于经纬度的截距 // 如果需要考虑截距,可以在这里添加相应的计算 return (latitude, longitude); } public static (double latitude, double longitude) UGUIToGeo(Vector3 ugui) { float x = ugui.x; float y = ugui.y; double latitude = (x + 40339.8622f) / 355.53f; double longitude = (y + 12420.05f) / 409.37f; return (latitude, longitude); } }