算法来确定城市名称的W / O上网吗? [英] Algorithm for determining city name w/o internet access?

查看:150
本文介绍了算法来确定城市名称的W / O上网吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有城市的数据库我的应用程序支持。这包括以下内容:

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


  • 名称。

  • 中心坐标。

最近的城市我的应用程序支持是pretty远。

Nearest cities my app support are pretty far away.

算法我想要实现的是:


  1. 获取当前位置

  2. 通过中心运行坐标,如果有的话是上述<(X)公里的用户,那么用户在那个城市

这是算法确定,或者我应该重新考虑它的一些其他的方式?我的应用程序目前支持3个城市,但是我打算升级&安培;支持更多的一些时间。

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.

推荐答案

您可以使用下面的逻辑来获得之间的距离的两个纬度长

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

(这是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))))

在哪里结果
    DEGTORAD = 57.29577951;

Radius= 6387.7;

可能是,类似的逻辑可以通过SQLite中DB原始查询实现的。

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.

这篇关于算法来确定城市名称的W / O上网吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆