Algorithm for determining city name w/o internet access?

南笙酒味 提交于 2019-12-14 03:34:07

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/23989909/algorithm-for-determining-city-name-w-o-internet-access

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!