简体   繁体   English

使用MongoDB和Spring数据进行地理位置搜索的测试数据

[英]Test Data for Geo Location Search using MongoDB and Spring Data

I am trying to implement Geo Location search using Mongo DB and Spring Data. 我正在尝试使用Mongo DB和Spring Data实现地理位置搜索。

I set up MongoDB correctly and enabled geo location index 我正确设置了MongoDB并启用了地理位置索引

db.track.ensureIndex( { start : "2d" } );

I created the following services : 我创建了以下服务:

  1. Search nearby from DB :http://localhost:8080/secure/track/get/11.53144/48.15672/0.5 从数据库搜索附近:http://localhost:8080/secure/track/get/11.53144/48.15672/0.5
  2. Add Location to DB http://localhost/secure/track/add 将位置添加到数据库http://localhost/secure/track/add

The values are getting added properly as i can see them in the DB. 我可以在数据库中看到正确添加的值。

My question is what test data should i use to test if i am getting list of objects nearby to a location.Since i am not well versed with latitude/longitude ,this will be of great help 我的问题是,如果要获取某个位置附近的对象列表,应该使用哪些测试数据进行测试。由于我不太熟悉纬度/经度,这将对您有很大帮助

This is not very clear for me: are you looking for a way to determine if the order of the POI returned is good? 这对我来说不是很清楚:您是否正在寻找一种方法来确定返回的POI顺序是否良好? If it is the case: 如果是这样:

There is a formula that will give you the distance between 2 points from their latitude/longitude. 有一个公式可以为您提供两个点之间的经度/纬度距离。

I found in this stackoverflow answer : 我在这个stackoverflow答案中找到了:

public static float distFrom(float lat1, float lng1, float lat2, float lng2) {
    double earthRadius = 6371; //kilometers
    double dLat = Math.toRadians(lat2-lat1);
    double dLng = Math.toRadians(lng2-lng1);
    double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
           Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
           Math.sin(dLng/2) * Math.sin(dLng/2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    float dist = (float) (earthRadius * c);
    return dist;
}

Then the best thing to do is to insert a batch of data that you know to be near your point of interest and check that the order is good. 然后,最好的办法是插入一批您知道在您的兴趣点附近的数据,并检查顺序是否正确。

I hope that answers your question.. Else, do not hesitate to edit or comment! 希望能回答您的问题。否则,请随时进行编辑或评论!

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

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