What if you extracted this to a function, which you called with the latitude and longitude, so you don't have a ton of javascript in your html?