Refactor google map JavaScript