本演示项目在Unity for Android Build中启用部分华为HMS和AGC服务,对应的类和函数的名称和用法相同。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

59 行
2.1 KiB

using System.Collections.Generic;
using System.Text;
using HuaweiService;
using HuaweiService.location;
using UnityEngine;
using UnityEngine.UI;
namespace HuaweiServiceDemo
{
public class GetLastLocationTest : Test<GetLastLocationTest>
{
private FusedLocationProviderClient mFusedLocationProviderClient;
public override void RegisterEvent(TestEvent registerEvent)
{
registerEvent("Get Last Location", () => GetLastLocation(false));
registerEvent("Get Last Location with Address", () => GetLastLocation(true));
}
public void GetLastLocation(bool withAddress)
{
mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(new Context());
try
{
Task lastLocation = null;
if (withAddress)
{
var request = new LocationRequest();
request.setPriority(200);
lastLocation = mFusedLocationProviderClient.getLastLocationWithAddress(request);
}
else
{
lastLocation = mFusedLocationProviderClient.getLastLocation();
}
lastLocation.addOnSuccessListener(new HmsSuccessListener<Location>((location) =>
{
if (location == null)
{
TestTip.Inst.ShowText("getLastLocation onSuccess location is null");
return;
}
TestTip.Inst.ShowText(
"getLastLocation onSuccess location[Longitude,Latitude]:" + location.getLongitude() + ","
+ location.getLatitude());
})).addOnFailureListener(new HmsFailureListener((Exception e) =>
{
TestTip.Inst.ShowText("getLastLocation onFailure "+ e.toString());
}));
}
catch (System.Exception e)
{
TestTip.Inst.ShowText("getLastLocation exception:" + e.Message);
}
}
}
}