Commits

Jakub Zalewski  committed 0deb923

javascript variables scope fix

  • Participants
  • Parent commits 952af57

Comments (0)

Files changed (1)

File easy_maps/templates/easy_maps/map.html

             if(navigator.geolocation && {{ use_html5_geolocation|lower }} && {% if map.address %}false{% else %}true{% endif %}) {
                 navigator.geolocation.getCurrentPosition(
                     function(position) {
-                        // user accepted
-                        geocoder = new google.maps.Geocoder();
+                        // user accepted                        
                         latlng = new google.maps.LatLng(position.coords.latitude,
                                                          position.coords.longitude);
                         mapSetup(latlng);
         }
         
         function latlngToAddress(latlng) {
+            var geocoder = new google.maps.Geocoder();
             geocoder.geocode({'latLng': latlng}, function(results, status) {
                 if (status == google.maps.GeocoderStatus.OK) {
                     if (results[0]) {
                       // Browser geolocation sucks, so let's agree on city and country.
                       var field = document.getElementsByClassName('vTextField')[0]; // FIXME: grab nearest one to the map
-                      address_parts = results[0].formatted_address.split(',');
-                      city_country = address_parts[address_parts.length-2] + ', ' + address_parts[address_parts.length-1];
+                      var address_parts = results[0].formatted_address.split(',');
+                      var city_country = address_parts[address_parts.length-2] + ', ' + address_parts[address_parts.length-1];
                       field.value = city_country;
                     }
                 }