如何获得从当前位置10的位置最近的
Im做的应用程序中,使用SQLite数据库文件获取数据。 表中分贝有店铺名称,地址,城市,纬度,经度等栏目。
Im doing app in which, uses sqlite db file to get data. table in db having shop name, address,city, latitude, longitude etc columns.
林抽到cureent位置的经度和纬度和也能够使用经度和纬度值来计算当前的位置和一个商店的位置(以db)之间的距离。
Im able to get cureent location latitude and longitude and also able to calculate the distance between current location and the location of a shop(in db) using longitude and latitude values.
下面我的问题是 我需要/显示10 shopnames(从数据库),这是最近的(距离)到当前位置。
Here my issue is I need to get/display 10 shopnames(from db) which are nearest(distance) to the current location.
请建议我或者给一个参考链接来解决这个问题。
Please suggest me or give a reference link to solve this issue
感谢您
有成千上万,让您的公式计算两点之间的距离站点。大多数人认为你想利用地球曲率考虑;没有说,这是简单的几何体(勾股定理)。在伪code:
There are thousands upon thousands of sites that give you the formulae for computing the distance between two points. Most assume you want to take curvature of the Earth into account; without that, it is simple geometry (Pythagorean theorem). In psuedocode:
的sqrt((X1-X2)^ 2 +(Y1-Y2)^ 2)
sqrt((x1-x2)^2 + (y1-y2)^2)
构造一个体现你的顺序选择哪个公式BY
条款,考虑到定点您正在搜索的纬度和经度的SQL查询。既然你不关心绝对距离,而是简单地距离的大小,你可以做一些东西,以节省CPU时间,如跳绳勾股定理的平方根的部分。
Construct a SQL query that embodies whichever formula you choose in its ORDER BY
clause, taking into account the latitude and longitude of the fixed point you are searching for. Since you do not care about absolute distance, but rather simply the magnitude of the distance, you may be able to do some stuff to save CPU time, such as skipping the square root part of the Pythagorean theorem.
要限制结果设置为10,使用 LIMIT 10
在查询中,你会得到前10名的点击率。
To limit the result set to 10, use LIMIT 10
in your query, and you will get the top 10 hits.