Database Reference
In-Depth Information
Search for Nearby Locations
To search for nearby locations (Figure 10-16 ), use the current user's location, obtained with get_user_location , and
then use the locations_within_distance . The Locations_within_distance method in Location service class uses a
method called distance to return a string value of the distance between the starting point and the respective location
(Listing 10-42).
Figure 10-16. Searching for Locations within a certain distance of User location
Listing 10-42. The locations_within_distance Method in the Location class
def locations_within_distance(neo, lq, mappedUserLocation,locationType)
cypher = " START n = node:geom({lq}) WHERE n.type = {locationType} " +
" 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"
results = neo.execute_query(cypher, {:lq => lq,:locationType => locationType} )
r=results["data"].map {|row| Hash[*results["columns"].zip(row).flatten] }
r.each do |e|
d = distance [e["lat"].to_f,e["lon"].to_f],[mappedUserLocation["lat"].
to_f,mappedUserLocation["lon"].to_f]
e.merge!("distanceToLocation" => d.to_s + " Miles Away")
end
r
end
 
Search WWH ::




Custom Search