计算指定区域的纬度经度范围 [英] calculate the latitude longitude range of a specified region

查看:196
本文介绍了计算指定区域的纬度经度范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在谷歌Android地图项目。我有用户的用户(经度和纬度)的地理位置的位置。我想计算的坐标区域与用户5公里(圈子),这样我可以从各地的用户数据库中筛选出的地方。有什么建议么?

I am working in android Google maps project. I have the Geo position of the user (latitude and longitude) of the user. I want to calculate the co-ordinates the region with in 5 km (circle) of the user so that I can filter out the places from the database around the user. Any suggestions?

推荐答案

纬度和经度的单位为度,所以你需要使用一个简单的平面地球投影。 重要:所有经/纬度下面的公式中值应在弧度,不度是平的地球是足够的,因为你的半径5公里!扁平地球投影为:

Latitude and Longitude are in degrees so you need to use a simple flat earth projection. IMPORTANT: all lat/lon values in the formula below should be in radians, not degrees! Using flat earth is adequate because your radius is 5km. The flat earth projection is:

var R = 6371; // km
var x = (lon2-lon1) * Math.cos((lat1+lat2)/2);
var y = (lat2-lat1);
var d = Math.sqrt(x*x + y*y) * R;

现在LAT1 / lon1是参考位置,在你的情况下,用户的位置。 LAT2 / lon2将是你正在测试的点。可变d为距离。由于R在千米被指定,那么D将在千米。

Now lat1/lon1 is the reference position, in your case, the position of the user. Lat2/lon2 would be the point your are testing. The variable 'd' is the distance. Since 'R' is specified in km, then 'd' will be in km.

如果'd'为少5(即小于5公里),该点在圆圈内。

If 'd' is less the 5 (ie, less than 5km), the point is inside the circle.

参考: http://www.movable-type.co.uk/脚本/ latlong.html

这篇关于计算指定区域的纬度经度范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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