简体   繁体   English

使用Java程序查找具有指定半径的给定纬度(即位置)周围的纬度和纬度值

[英]Find surrounding the latitude and latitude values of given latitude and longitude(i.e: location) with specified radius using java program

All latitude and longitude values (including current location and other locations) are varchar datatype in mysql db table. 所有的纬度和经度值(包括当前位置和其他位置)都是mysql db表中的varchar数据类型。 I am struggling to get all maximum and minimum latitude/longitude values that are within 2km or 5km radius of current location. 我正在努力获取当前位置2公里或5公里半径内的所有最大和最小纬度/经度值。 My current location latitude and longitude values and other location lat/long values are stored into mysql db table using google map api. 我当前的位置纬度和经度值以及其他位置经/纬度值使用Google Map API存储到mysql db表中。

I need to fetch the location records (max/min latitude/longitude values)which are all within given radius of current location from table. 我需要从表中获取所有位于当前位置给定半径内的位置记录(最大/最小纬度/经度值)。

Input : 输入:

Location : AA (or) Lat: 12.561 and Lon : 77.48 Radius /Distance : 2km 位置:机管局(或)纬度:12.561和朗:77.48半径/距离:2公里

Table : 表:

Location | 位置| Lat | 纬度| Long

AA | AA | 12.561 | 12.561 | 77.48 77.48

A2 | A2 | 12.567 | 12.567 | 77.489 77.489

A4 | A4 | 12.59 | 12.59 | 78.42 78.42

A6 | A6 | 12.57 | 12.57 | 77.45 77.45

Output : 输出:

List of Location name which is satisfied above condition. 满足以上条件的位置名称列表。

It would be great help, if you will give few line of java code. 如果您只提供几行Java代码,那将是非常有帮助的。

I need to get the o/p of lat/long values all direction (N/E/S/W) without using bearing value as my application don't have bearing value. 我需要获取所有方向上的经/纬度值的o / p(N / E / S / W),而不使用方位角值,因为我的应用程序没有方位角值。 It should get output values only using input of current location latitude /longitude and distance/radius value. 仅应使用当前位置的纬度/经度和距离/半径值的输入来获取输出值。

You will need to change coordinates from Varchar to DECIMAL(8, 6) to allow to calculate distance. 您需要将坐标从Varchar更改为DECIMAL(8,6)才能计算距离。

The following SQL query uses Spherical Law of Cosines to calculate the distance between a coordinate and coordinates in a table. 以下SQL查询使用余弦球法则来计算坐标与表中坐标之间的距离。

d = acos( sin(φ1).sin(φ2) + cos(φ1).cos(φ2).cos(Δλ) ).R d = acos(sin(φ1).sin(φ2)+ cos(φ1).cos(φ2).cos(Δλ)).R

The query uses MySQL Math functions 该查询使用MySQL Math函数

"SELECT Location,Lat,Long,(6367 * acos( cos( radians(center_lat) )
  * cos( radians( Lat ) ) * cos( radians( Long ) - radians(center_long) )
  + sin( radians(center_lat) ) * sin( radians( Lat ) ) ) ) AS distance FROM table 
  HAVING distance < radius ORDER BY distance ASC LIMIT 0 , 20"

Where center_lat & center_long are coordinates of given point 其中center_latcenter_long是给定点的坐标

PS use 3956 for miles 6367 for kms PS使用3956达到6367英里/公里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM