detect location generation function and working version