public async Task <bool> VerifyLocation() { Loc loc = await GetLocationFromDevice(); // If MEX is reachable on your SIM card: string aCarrierName = GetCarrierName(); string eCarrierName; if (me.useOnlyWifi) // There's no host (PC, UnityEditor, etc.)... { eCarrierName = carrierName; } else { eCarrierName = aCarrierName; } VerifyLocationRequest req = me.CreateVerifyLocationRequest(eCarrierName, loc, cellID, tags); VerifyLocationReply reply = await me.VerifyLocation(req); // The return is not binary, but one can decide the particular app's policy // on pass or failing the location check. Not being verified or the country // not matching at all is on such policy decision: // GPS and Tower Status: switch (reply.gps_location_status) { case VerifyLocationReply.GPSLocationStatus.LOC_ROAMING_COUNTRY_MISMATCH: case VerifyLocationReply.GPSLocationStatus.LOC_ERROR_UNAUTHORIZED: case VerifyLocationReply.GPSLocationStatus.LOC_ERROR_OTHER: case VerifyLocationReply.GPSLocationStatus.LOC_UNKNOWN: return(false); } switch (reply.tower_status) { case VerifyLocationReply.TowerStatus.NOT_CONNECTED_TO_SPECIFIED_TOWER: case VerifyLocationReply.TowerStatus.TOWER_UNKNOWN: return(false); } // Distance? A negative value means no verification was done. if (reply.gps_location_accuracy_km < 0f) { return(false); } // A per app policy decision might be 0.5 km, or 25km, or 100km: if (reply.gps_location_accuracy_km < 100f) { return(true); } // Too far for this app. return(false); }
async Task <bool> DoFindCloudlet() { bool ok = false; MatchingEngine dme = mexSample.dme; VerifyLocationReply reply = null; try { var deviceSourcedLocation = await LocationService.RetrieveLocation(); if (deviceSourcedLocation == null) { Debug.Log("VerifyLocation must have a device sourced location to send to DME."); return(false); } Debug.Log("Device sourced location: Lat: " + deviceSourcedLocation.latitude + " Long: " + deviceSourcedLocation.longitude); var verifyLocationRequest = dme.CreateVerifyLocationRequest( mexSample.carrierName, // TODO: carrierName is the current carrier string, and must be provided by the app. deviceSourcedLocation); reply = await dme.VerifyLocation(mexSample.host, mexSample.port, verifyLocationRequest); statusContainer.Post("VerifyLocation Reply mobile tower status: " + reply.tower_status.ToString()); if (reply.tower_status.Equals(FindCloudletReply.FindStatus.FIND_FOUND.ToString())) { ok = true; } } catch (System.Net.WebException we) { Console.WriteLine(we.StackTrace); statusContainer.Post(we.Source + ", WebException: " + we.Message); statusContainer.Post(we.StackTrace); } finally { if (reply != null) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(VerifyLocationReply)); MemoryStream ms = new MemoryStream(); serializer.WriteObject(ms, reply); string jsonStr = Util.StreamToString(ms); statusContainer.Post("VeryfyLocation Reply: " + jsonStr); } } return(ok); }