Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a database of Cities my application supports. This includes following:

  • Name.
  • Center coordinates.

Nearest cities my app support are pretty far away.

Algorithm I want to implement is:

  1. Get current location
  2. Run through center coordinates, if anything is in <(X)Km from the user, then user is in that city.

Is this algorithm OK or should I re-think it some other way? My app currently supports 3 cities, however I plan to escalate & support more in some time.

Unfortunately, my main audience is abroad public, so internet access is kind of limited, e.g. I would implement an algorithm to determine my city name from internet using standard mechanic, but I can't relay on it as a default algorithm.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
159 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use the following logic to get the distance between two lat long

(This is for oracle)

DISTANCE   =  (NVL(Radius,0) * ACOS((sin(NVL(Lat1,0) / DegToRad) * SIN(NVL(Lat2,0) / DegToRad)) +
    (COS(NVL(Lat1,0) / DegToRad) * COS(NVL(Lat2,0) / DegToRad) *
     Cos(Nvl(Lon2,0) / Degtorad - Nvl(Lon1,0)/ Degtorad))))

Where
DEGTORAD = 57.29577951;

Radius= 6387.7;

May be, similar logic can be implemented via a raw Query in SQLite DB.

The distance can be calculated and ranked and sorted based on least distance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...