Beispiel #1
0
    /**<summary> Show location selection dialog </summary>*/
    public void SelectLocationDialog()
    {
        DialogManager.ShowSimple("Select building manually", buildings.Select(b => b.name).ToArray(), !buildingID.IsNullOrEmpty(),
                                 async(int selectedIndex) => {
            NativeMethods.ShowToast(buildings[selectedIndex].name + " selected");

            buildingID = buildings[selectedIndex].buildingID;
            Tuple <bool, Area[]> areasResult = await ServerAPI.Areas(buildingID);
            OnAreasResponse(areasResult.Item1, areasResult.Item2);
        });
    }
Beispiel #2
0
    /**<summary> Get buildings from Location API </summary>*/
    private async Task Buildings()
    {
        Tuple <bool, Building[]> result = new Tuple <bool, Building[]>(false, null);

        result = await ServerAPI.Buildings();

        buildings = result.Item2;
        Vector2 currentLocation = ServerAPI.LastGPSLocation();

        Building closestBuilding = new Building();
        float    closestDistance = distanceLimit;

        // Get closest building compared to gps location
        Array.ForEach(buildings, (Building b) =>
        {
            float distance = DistanceBetween(currentLocation, b.location);
            if (distance < closestDistance)
            {
                closestBuilding = b;
                closestDistance = distance;
            }
        });

        if (App.config.debug)
        {
            Debug.Log("Closest building\n" + closestBuilding + " with distance: " + closestDistance);
        }

        if (closestDistance <= distanceLimit)
        {
            buildingID = closestBuilding.buildingID;
            // Get areas of building
            Tuple <bool, Area[]> areasResult = await ServerAPI.Areas(buildingID);

            OnAreasResponse(areasResult.Item1, areasResult.Item2);
        }
        else
        {
            NativeMethods.ShowToast("Couldn't find building within " + distanceLimit * 100 + " meters");
            SelectLocationDialog();
        }
    }