Two ways:
1. Your phone doesn’t need to connect to a WiFi network to know that it is close by. Your phone always listens for networks and uses them to determine where it is. Your phone can do this even when WiFi is turned off.
2. Your phone probably has built in GPS which it uses to determine where it is.
Latest Answers