Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting Which Floor the User is on in a Building in Swift

I am developing the application where the application has to detect which floor the user is on in a building.

I have tried using CLLocation (location.floor?.level) but this value always returns nil.

Please suggest me if there is any other way to get floor level.

like image 366
Nilesh Avatar asked Oct 28 '25 13:10

Nilesh


1 Answers

TL, DR: unless your location is on the indoor mapping list, floor will be nil.

While it's true that GPS doesn't work indoor, iOS has other tricks to determine users' location when they are inside buildings. You can still get the latitude, longitude and altitude of the user.

The real reason is your location doesn't support indoor mapping. The altitude is measured in meters above / below sea level. Not all cities, or even neighborhoods in the same city, are at the same sea level. Some buildings have taller floors than others. It requires extra work to get that information and Apple has not done that for your location.

like image 150
Code Different Avatar answered Oct 31 '25 04:10

Code Different