Using Couchbase GeoSpatial and SpringData

Hello,

I’m trying to implement in my app a geolocation service through Couchbase & SpringData but I’m facing issues that I can’t solve :confused:

Let me explain, I have a repository called PersonRepository :

 public interface PersonRepository extends CrudRepository<Person, String> {

@Dimensional(dimensions=2, designDocument="dev_userSpatial", spatialViewName="byLocation")
	    Set<Person> findByLocationNear(Point location,Distance distance);

}

Then a PersonService Interface and his implementation :

public interface PersonService {
    Person getPersonById(String id);
    void delete(Person person);
    void create(Person person);
    List<Person> getPersonByFirstName(String firstName);
    List<Person> findByAge(String age);
    List<Person> findAll();
	Set<Person> findByLocationNear(Point location, Distance distance);
} 


@Service
public class PersonServiceImpl implements PersonService{
    @Autowired
    private PersonRepository personRepository;

@Override
public Person getPersonById(String id) {
	return personRepository.findById(id).orElse(new Person());
}
@Override
public void delete(Person person) {
	personRepository.delete(person);
}
@Override
public void create(Person person) {
	personRepository.save(person);
}

@Override
public List<Person> getPersonByFirstName(String firstName) {
	return personRepository.findByFirstName(firstName);
}
@Override
public List<Person> findByAge(String age) {
	return null;
}
@Override
public Set<Person> findByLocationNear(Point location,Distance distance) {
	return personRepository.findByLocationNear(location, distance);
}
@Override
public List<Person> findAll() {
	List<Person> persons = new ArrayList<Person>();
	Iterator<Person> it = personRepository.findAll().iterator();
	while(it.hasNext()) {
		persons.add(it.next());
	}
	return persons;
}

}

And now in my Controller I invoke my findByLocationNear method like this :

Set<Person>personsNearMe=personService.findByLocationNear(newPoint(4.8046,45.7712),newDistance(10,Metrics.KILOMETERS));

Then I’ve activated Log with Debug level and I see that request
Executing spatial view query: stale=false&start_range=[4.803032144057112,45.76963214405711]&end_range=[4.8061678559428875,45.77276785594289]

and when I see on the map these start_Range & End_Range coordonates are not separated by 10km but by 430 meters and I’m not getting any documents returned cause i’m not in the good range.

My Spatial view function is configured like this :

 function (doc,meta) {
  if (doc.location &&
      doc._class == "com.myapp.app.user.documents.Person") {
    emit([doc.location.x, doc.location.y], null);
  }
}

Any idea how to solve this ?

Thank you all :slight_smile: ,