I'm uncertain what you mean by "first access" and "second access". Can you tell us the exact steps to reproduce? When/from where are the first two lines run?
- I would reverse the order of the params check, though probably not the cause here.
- You should also check the available parameter. It will be 0 if the hardware is not present, permission is not granted, etc. There is no point in trying 5 times in that case!
- What does LocationGps() do?
if @params['status'] == 'ok' && @params['known_position'].to_i != 0