using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class UpdateDemo : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
public RectTransform m_bg;
public RectTransform m_center;
private Vector2 m_localCursor;
public float lat1;
public float lon1;
public float lat2;
public float lon2;
public char unit;
private void Start()
{
double dis = DistanceBetweenPoint(lat1, lon1, lat2, lon2, unit);
Debug.LogError("dis=" + dis);
}
public void OnPointerDown(PointerEventData eventData)
{
Debug.LogError("OnPointerDown");
{
Debug.LogError("in image");
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_bg, Input.mousePosition, Camera.main, out m_localCursor);
m_center.anchoredPosition = m_localCursor;
}
}
public void OnPointerUp(PointerEventData eventData)
{
Debug.LogError("OnPointerUp");
}
public double DistanceBetweenPoint(float lat1, float lon1, float lat2, float lon2, char unit)
{
if ((lat1 == lat2) && (lon1 == lon2))
{
return 0;
}
else
{
double theta = lon1 - lon2;
double dist = Math.Sin(deg2rad(lat1)) * Math.Sin(deg2rad(lat2)) + Math.Cos(deg2rad(lat1)) * Math.Cos(deg2rad(lat2)) * Math.Cos(deg2rad(theta));
dist = Math.Acos(dist);
dist = rad2deg(dist);
dist = dist * 60 * 1.1515;
if (unit == 'K')
{
dist = dist * 1.609344;
}
else if (unit == 'N')
{
dist = dist * 0.8684;
}
return (dist);
}
}
private double deg2rad(double deg)
{
return (deg * Math.PI / 180.0);
}
private double rad2deg(double rad)
{
return (rad / Math.PI * 180.0);
}
}
经纬度计算距离: https://www.geodatasource.com/developers/c-sharp 代码 https://tool.box3.cn/lbs.html 经纬度计算距离 https://jingyan.baidu.com/article/f7ff0bfc7fed532e26bb1394.html 百度地图查询经纬度方法
|