Deny location based access to nodes I need to restrict access to a node based on the distance of the current user to a location attached to the node (with Location module). The distance to decide, if access is allowed is node based and stored in a field of the node.
Currently I achive this feature with hook_node_access(). I get the current location of the user through the Smart IP module and are able to calculate the distance by passing the coordinates of the user and the node to location_distance_between(), which is provided by the Location module.

Because hook_node_access() isn't considered by Views I think about accomplishing this feature with hook_node_access_records() and hook_node_grants(). Since the distance is dynamically, I have no idea how to achive this. In my understanding hook_node_grants() is called before the database query, so I have no chance to get the distance right?

Any ideas?

Thanks, Daniel
Option 1

I use the Geofield module, which provides a similar function to the Location module.  It provides the concept of a proximity filter.  This allows you to implement views such as "show all nodes within 50km of specified point".  I don't know whether the Location module has a similar function, or whether you might be willing to change modules.  The Smart IP module claims some Views integration but D6 only, so you might need a bit of code to integrate with views.

This approach would not use access control at all - so that if the user specifically navigated by URL to a far away node, they would still see it.

Option 2

If you definitely want access control, then I think you will have to give up exact distances.  You could divide your target area into regions, maybe around 50-500 of them - most simply using a simple grid.  In your hook_node_access_records, you decide which regions are close enough to the node (calculate distance to the region centre).  Finally in hook_node_grants, you need code to take the output of the Smart IP module and calculate which region it is in, and set the appropriate grant.

If you need some more help with the details of either approach, feel free to edit your question to say which approach you prefer, what you have working and where you are stuck.