Get track of rails using GPS option

I would like to create a route in my rails application to handle the gps coordinate parameter. The goal is to find restaurants near this position.

This is what I started:
match "/restaurants/near/:lat/:lng(/:range)", :to => "restaurants#near", :as => "near", :constraints => {:range => /\d+/}

The router seems to have problems with float parameters, the URL / restaurants / near / 53.0123 / 10.5678 is not recognized. Do you have a solution or best practice for handling GPS coordinates in rails urls?

Thanks!

+6
source share
1 answer

The problem is caused by the fact that Rails is trying to use "dots" to find the format (.:format) Thus, you can add some restrictions to fix it, for example:

 match "/restaurants/near/:lat/:lng(/:range)", :to => "restaurants#near", :as => "near", :constraints => {:lat => /\-?\d+(.\d+)?/, :lng => /\-?\d+(.\d+)?/ , :range => /\d+/} 
+11
source

Source: https://habr.com/ru/post/885654/


All Articles