Database Reference
In-Depth Information
graphStory.setLocations(graphStoryDAO.getLocationDAO()
.
returnLocationsWithinDistanceAndHasProduct
(
mappedUserLocation.getLat(),
mappedUserLocation.getLon(),
distance,
Long.valueOf(productNodeId)
));
graphStory.setProduct(graphStoryDAO
.getProductDAO().getProductByNodeId(Long.valueOf(productNodeId)));
} else {
graphStory.setLocations(graphStoryDAO.getLocationDAO()
.
returnLocationsWithinDistance
(
mappedUserLocation.getLat(),
mappedUserLocation.getLon(), distance)
);
}
}
}
catch (Exception e) {
log.error(e);
}
return SUCCESS;
}
Search for Nearby Locations
To search for nearby locations, as shown in Figure
12-16
, use the current user's location, obtained with
getUserLocation
, and then use the
locationsWithinDistance
method. The
returnLocationsWithinDistance
method in the
LocationDAO
class uses a method called
addDistanceTo
, which returns a string value of the distance
between the starting point and the respective location (Listing 12-41).
Listing 12-41.
The
returnLocationsWithinDistance
Method
public List<MappedLocation> returnLocationsWithinDistance(Double lat, Double lon, Double distance) {
try {
ResultSet rs = cypher.resultSetQuery(
"START n = node:geom({1}) WHERE NOT(has(n.type)) " +
" RETURN n.locationId as locationId, n.address as address, " +
" n.city as city, n.state as state, n.zip as zip, " +
" n.name as name, n.lat as lat, n.lon as lon",
map("1", distanceQueryAsString(lat, lon, distance)));
ResultSetMapper<MappedLocation> resultSetMapper =
new ResultSetMapper<MappedLocation>();
List<MappedLocation> locations = resultSetMapper
.mapResultSetToListMappedClass(rs, MappedLocation.class);