You are here:

Advanced Math/how do apps calculate nearby supermarkets?

Advertisement


Question
hello there - i would like to know, using a gps in mobile phones, how would i calculate from a certain location, how far out is a supermarket from me. i want to know say within a 10 mile radius how far a supermarket is from me?

what formula will I need to generate? Please help.

thank you.
craig,

Answer
A GPS will provide you with the traveling distance to the supermarket, but not the distance "as the crow flies." There are obstacles such as buildings and rivers that add to the distance calculated by the GPS.

You can obtain the latitude and longitude of the two points from the GPS, then use the Haversine formula to approximate the actual distance:

a = sin²(Δφ/2) + cos(φ1).cos(φ2).sin²(Δλ/2)
c = 2.atan2(√a, √(1−a))
d = R.c
where   φ is latitude, λ is longitude, R is earth’s radius (mean radius = 6,371km)
   note that angles need to be in radians to pass to trig functions!

The equations above are from http://www.movable-type.co.uk/scripts/latlong.html.

Note that the Haversine formula accounts for the overall curvature of the earth's surface, but not, of course, for local changes in elevation.  

Advanced Math

All Answers


Answers by Expert:


Ask Experts

Volunteer


Janet Yang

Expertise

I can answer questions in Algebra, Basic Math, Calculus, Differential Equations, Geometry, Number Theory, and Word Problems. I would not feel comfortable answering questions in Probability and Statistics or Topology because I have not studied these in depth.

Experience

I tutor students (fifth through twelfth grades) and am a Top Contributor on Yahoo!Answers with over 24,000 math solutions.

Publications
Co-author of An Outline of Scientific Writing: For Researchers With English as a Foreign Language

Education/Credentials
I have a Bachelor's degree in Applied Mathematics from the University of California at Berkeley.

Past/Present Clients
George White Elementary School. Homework Help program at the Ridgewood Public Library, Ridgewood, NJ. Individual students.

©2016 About.com. All rights reserved.