A Framework for Indoor Localization Using the Magnetic Field