GPSTool.cs 747 B

12345678910111213141516171819202122232425
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class GPSTool
  5. {
  6. //GPS获取地址
  7. //成功返回:string[]{国,省,市}
  8. //失败返回:null
  9. public static string[] GetAddress()
  10. {
  11. string[] address = null;
  12. using (var clsU3D = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  13. {
  14. using (var objCtx = clsU3D.GetStatic<AndroidJavaObject>("currentActivity"))
  15. {
  16. using (var objGPSTool = new AndroidJavaClass("com.example.smartbowlib.GPSTool"))
  17. {
  18. address = objGPSTool.CallStatic<string[]>("getAddress", objCtx);
  19. }
  20. }
  21. }
  22. return address;
  23. }
  24. }