Your question is too broad.
First: new phones may have NFC support. So you need to know how to NFC
Secondly: in case the phones do not have NFC, you will have to use GPS and gryo-based sensor information. To improve the algorithm, you should consider using Bearing, Altitude, etc.
source share