This commit is contained in:
2020-07-04 14:41:25 +08:00
parent 70c346d2c1
commit a8f02e4da5
3748 changed files with 587372 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
using System;
using System.Collections;
using UnityEngine;
using Coolape;
public static class LBSUtl
{
//将tile(瓦片)坐标系转换为LatLngt(地理)坐标系pixelXpixelY为图片偏移像素坐标
public static LatLng TileXYToLatLng(int tileX, int tileY, int zoom, int pixelX = 0, int pixelY = 0)
{
double size = Math.Pow(2, zoom);
double pixelXToTileAddition = pixelX / 256.0;
double lng = (tileX + pixelXToTileAddition) / size * 360.0 - 180.0;
double pixelYToTileAddition = pixelY / 256.0;
double lat = Math.Atan(Math.Sinh(Math.PI * (1 - 2 * (tileY + pixelYToTileAddition) / size))) * 180.0 / Math.PI;
return new LatLng(lng, lat);
}
//将LatLngt地理坐标系转换为tile瓦片坐标系pixelXpixelY为图片偏移像素坐标
public static void LatLngToTileXY(LatLng latlng, int zoom, out int tileX, out int tileY, out int pixelX, out int pixelY)
{
double size = Math.Pow(2, zoom);
double x = ((latlng.Longitude + 180) / 360) * size;
double lat_rad = latlng.Latitude * Math.PI / 180;
double y = (1 - Math.Log(Math.Tan(lat_rad) + 1 / Math.Cos(lat_rad)) / Math.PI) / 2;
y = y * size;
tileX = (int)x;
tileY = (int)y;
pixelX = (int)((x - tileX) * 256);
pixelY = (int)((y - tileY) * 256);
}
}
public class LatLng
{
public double Longitude = 0;
public double Latitude = 0;
public LatLng(double Longitude, double Latitude)
{
this.Longitude = Longitude;
this.Latitude = Latitude;
}
public override string ToString()
{
return "Longitude:" + Longitude + ", Latitude:" + Latitude;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a238b9104fb9e46c9a25cd66859db12b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,129 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Coolape;
using UnityEngine.Android;
/// <summary>
/// My location.通过百度定位取得定位信息
/// </summary>
public class MyLocation : MonoBehaviour
{
public static MyLocation self;
public object callback;
public string ak4Ios = "B6gC5ufYoGSkM83NUA3qUzebhNT2hmWj"; //B6gC5ufYoGSkM83NUA3qUzebhNT2hmWj
public MyLocation()
{
self = this;
}
public int coorType = 0;
public class CoorType
{
public const int BD09ll = 0; // 百度经纬度坐标
public const int BD09 = 1; // 百度墨卡托坐标
public const int WGS84 = 2; //
public const int GCJ02 = 3; //国测局坐标
public const string BD09llName = "bd09ll"; // 百度经纬度坐标
public const string BD09Name = "bd09"; // 百度墨卡托坐标
public const string WGS84Name = "wgs84"; //
public const string GCJ0Name = "gcj02"; //国测局坐标
public static string getCoorTypeName(int type)
{
switch (type)
{
case 0:
return BD09llName;
case 1:
return BD09Name;
case 2:
return WGS84Name;
default:
return GCJ0Name;
}
}
}
#if !UNITY_EDITOR && UNITY_IOS
[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern void _init(string ak, string goName, int coorType);
[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern void _getMyLocation();
#endif
#if UNITY_ANDROID
static AndroidJavaClass _androidJavaClass;
public static AndroidJavaClass androidJavaClass
{
get
{
if (_androidJavaClass == null)
_androidJavaClass = new AndroidJavaClass("com.tianrun.BaiduLBS");
return _androidJavaClass;
}
}
#endif
public void init(int coorType)
{
this.coorType = coorType;
#if UNITY_ANDROID
androidJavaClass.CallStatic("init", gameObject.name, CoorType.getCoorTypeName(coorType));
#elif UNITY_IOS
_init(ak4Ios, gameObject.name, coorType);
#endif
}
public void guidSwitchGps()
{
#if UNITY_ANDROID
androidJavaClass.CallStatic("guidSwitchGps");
#endif
}
string[] permissions = new string[]
{
"android.permission.ACCESS_FINE_LOCATION",
"android.permission.ACCESS_COARSE_LOCATION",
"android.permission.INTERNET",
"android.permission.READ_PHONE_STATE",
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.ACCESS_NETWORK_STATE",
"android.permission.CHANGE_WIFI_STATE",
};
public void checkUserPermission()
{
#if UNITY_ANDROID
for (int i = 0; i < permissions.Length; i++)
{
if (!Permission.HasUserAuthorizedPermission(permissions[i]))
{
Permission.RequestUserPermission(permissions[i]);
}
}
#endif
}
public void getMyLocation(object callback)
{
checkUserPermission();
this.callback = callback;
#if UNITY_ANDROID
androidJavaClass.CallStatic("getMyLocation", CoorType.getCoorTypeName(coorType));
#elif UNITY_IOS
_getMyLocation();
#endif
}
void onCallback(string json)
{
//Hashtable map = JSON.DecodeMap(json);
Utl.doCallback(callback, json);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a2e4e1935fee1443cb393cbd8e570c5e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: