Check-in Inside a Building
Now that we have the power to select a floor, we can provide a more powerful constraint to the NEON Location Service that includes the building and floor that we are checking into. Once a user has been located inside a building structure, the NEON Location Service can detect transitions between floors in that building and track you throughout the structure.
Let’s enhance our user correction to check if we are applying it inside a building with a particular floor selected. When the user constraint is applied and it’s inside a building outline, we will find out the displayed floor and apply a constraint in that building on that floor:
We loop through the buildings in our hashmap and check if the check-in was inside any of them. For the contains check, we use the android maps utils library, so you’ll need to add the following line to your dependencies in build.gradle:
implementation 'com.google.maps.android:android-maps-utils:0.5'
Now replace the user correction code with this:
case R.id.action_user_correction:
if (!isCorrectingLocation) {
// initialize user correction-mode
userCorrectionMenu.setTitle(R.string.user_confirm_title);
cancelCorrectionMenu.setVisible(true);
settingsMenu.setVisible(false);
isCorrectingLocation = true;
findViewById(R.id.image_user_correct).setVisibility(View.VISIBLE);
} else {
// user location has been set, undo correction-mode and perform constraint
cancelUserCorrection();
//get latitude and longitude of correction
LatLng target = new LatLng(mMap.getCameraPosition().target.latitude, mMap.getCameraPosition().target.longitude);
//find the building floor that the user is checking in on top of
Integer floor = null;
UUID buildingID = null;
for(BuildingOverlays bo : buildingHashMap.values())
{
//find building intersection
if(PolyUtil.containsLocation(target,bo.outlines.get(0).getPoints(), false))
{
//set floor
floor = bo.floor;
buildingID = bo.building.getID();
break;
}
}
if(floor != null && buildingID != null)
NeonConstraint.addUserCheckin(System.currentTimeMillis(), target.latitude, target.longitude, 1.0f, ElevationInfo.OnFloor(buildingID, floor));
else NeonConstraint.addUserCheckin(System.currentTimeMillis(), target.latitude, target.longitude, 1.0f, ElevationInfo.None());
}
return true;
If we are able to calculate a building and floor for your check-in, then we can use NeonConstraint.addUserCheckin() with ElevationInfo.OnFloor(building, floor) and specify the position, building, and floor. Otherwise, we assume we’re outside and use ElevationInfo.None().