不能回答a),但對於b),得到2個座標之間的距離,如果它小於兩個半徑的總和,則它是匹配的(即重疊)。
獲取距離:
public static double GetDistance(double latitude1, double longitude1, double latitude2, double longitude2, DistanceUnits distanceUnits = DistanceUnits.Miles)
{
try
{
// Earth radius in kilometers via NASA as of 2016 - https://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html
const double earthRadiusKilometers = 6378.137;
var latRadians = (latitude2 - latitude1).ToRadians();
var lonRadians = (longitude2 - longitude1).ToRadians();
var a = Math.Sin(latRadians/2) *
Math.Sin(latRadians/2) +
Math.Cos(latitude1.ToRadians()) *
Math.Cos(latitude2.ToRadians()) *
Math.Sin(lonRadians/2) *
Math.Sin(lonRadians/2);
var radianDistance = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a)));
switch (distanceUnits)
{
case DistanceUnits.Kilometers:
{
return radianDistance * earthRadiusKilometers;
}
case DistanceUnits.Miles:
{
return radianDistance * ConvertKilometersToMiles(earthRadiusKilometers);
}
}
return radianDistance;
}
catch
{
return double.MaxValue;
}
}
public static double ConvertKilometersToMiles(double kilometers)
{
return kilometers * 0.621371192;
}
public enum DistanceUnits
{
Miles,
Kilometers,
Radians
}
難道這一切是發生在內存雖然不Lucene的一部分?這是我特別想要解決的lucene搜索方面。 –
您可以在發佈時進行計算,將結果添加到盧塞恩索引中。 –