Android的 - 如何从我的数据库是在我的位置在一定范围内是什么这些位置? [英] Android - How to get those locations from my database what are within a given distance around my location?

查看:193
本文介绍了Android的 - 如何从我的数据库是在我的位置在一定范围内是什么这些位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了很多解决方案,以计算两个位置之间的距离,就像
如何找到两个geopoints之间的距离?
要么
<一href=\"http://stackoverflow.com/questions/8049612/calculating-distance-between-two-geographic-locations\">Calculating两个地理地点之间的距离
或者更具体的,这里有一个code为.distanceTo方法:

I found a lot of solutions to calculate the distance between two locations, just like how to find the distance between two geopoints? or Calculating distance between two geographic locations or to be more specific, here's a code for the .distanceTo method:

Location locationA = new Location("point A");

locationA.setLatitude(pointA.getLatitudeE6() / 1E6);
locationA.setLongitude(pointA.getLongitudeE6() / 1E6);

Location locationB = new Location("point B");

locationB.setLatitude(pointB.getLatitudeE6() / 1E6);
locationB.setLongitude(pointB.getLongitudeE6() / 1E6);

double distance = locationA.distanceTo(locationB);

如果我有一个位置(比如说locationA),我有POI定位数据的数据库,而我感兴趣的只有这些,是什么周围一定距离内的位置locationA(让我们说距离),我该如何获得这些?

If I have a location (let's say "locationA"), and I have a database with POI-location data, and I'm interested in only those, what are around that location "locationA" within a given distance (let's say "distance"), how do I get those?

如果我写一个方法

private Location[] poiAroundMe (Location locationA, double distance) {
   // The necessary calculation
   return locationsAroundMeWithinTheGivenDistance[];
}

什么是必要的计算?

what would be "the necessary calculation"?

我是pretty肯定的,那有对于没有内置的方法,所以我想寻求帮助。

I'm pretty sure, that there's no built-in method for that, so I would like to ask for help.

感谢您!

推荐答案

做一个选择你的数据库,让所有这一切都是恰好包括你的距离圈一平方内的位置。

Do a select on your database, to get all the locations which are inside of a square that includes exactly your "distance-circle".

SELECT * 
FROM TblLocations 
WHERE longitude < x 
AND longitude > y 
AND latitude < a
AND latitude > b;

将一个数组中的数据,并把它交给你的poiAroundMe() - 方法。
在里面你可以与你已经知道calcualte法检查每一个的距离,你locationA并过滤所有,其中有一个小的距离,你locationA并把它们放到你的locationsAroundMeWithinTheGivenDistance []

Put the data in a array, and give it to your poiAroundMe() -Method. Inside you can check each for the distance to your locationA with a calcualte-method you already know and filter all, which have a smaller distance to your locationA and put them into your locationsAroundMeWithinTheGivenDistance[]

这不是那样干净,你也许愿意,但它会工作,我认为。 ;)

It's not as clean as you perhaps wish, but it will work i think. ;)

这篇关于Android的 - 如何从我的数据库是在我的位置在一定范围内是什么这些位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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