开发者

Android Location Promixity Query

开发者 https://www.devze.com 2023-01-07 13:36 出处:网络
I\'m working on an app, where I need to determine which sqlite rows are closest to me given my current lat/long. I have a table with lat and long columns, I\'m just having a bit of trouble working out

I'm working on an app, where I need to determine which sqlite rows are closest to me given my current lat/long. I have a table with lat and long columns, I'm just having a bit of trouble working out how to get ones that are closest based on my dev开发者_如何学编程ices current location. Any help would be appreciated.


In this kind of situations you can use the Manhatten Distance. Let's suppose your current position is:

myPosition_Lat = XX
myPosition_Long = YY

And, that you have an array with the all the coordinates (all_stops[]). You just have to go over all items in all_stops[] and calculate the distance to myPosition, and save the minimum distance this way:

distance = Math.abs(myPosition_Lat - the_Lat) + Math.abs(myPosition_Long – the_Long);

Here the_Lat and the_Long contain the latitude and longitud you are calculating with.

0

精彩评论

暂无评论...
验证码 换一张
取 消