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"); })); } catch (System.Exception e) { TestTip.Inst.ShowText("getLastLocation exception:" + e.Message); } }
public void GetLastLocation() { mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(new Context()); try { Task 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"); })); } catch (System.Exception e) { TestTip.Inst.ShowText("getLastLocation exception:" + e.Message); } }