Google Maps API Latitude / longitud pareja a las tablas de fusión de Google Consulta -- javascript campo con jquery campo con geospatial campo con google-maps camp codereview Relacionados El problema

Google Maps API latitude/longitude pair to Google Fusion Tables query


6
vote

problema

Español

Estoy tratando de aprender JavaScript, y como una herramienta de práctica, recientemente escribí un aplicación web simple que usa el geocoder de la API de Google Maps para obtener la latitud y la longitud de una ubicación (entrada de usuario), manipularlos, luego consultar a aquellos contra una tabla de fusión de Google que enumeran los códigos de la zona climática del mundo según a la Clasificación de clima de Köppen-Geiger . Básicamente, las personas pueden escribir en una ubicación y descubrir qué es la zona climática, y ver un mapa con las zonas superpuestas si lo desean (pueden ser de interés para las pulseras de geografía).

Toda la lógica está copiada en un archivo JavaScript a continuación. Mi objetivo era escribir la mayor cantidad de eso sin jQuery posible, por lo que solo uso jquery para manejar la solicitud de las tablas de fusión y agregar / eliminar las clases.

Lo he ejecutado a través de Jshint, y se solucionó la mayoría de las cosas mencionadas allí. Tuve el tiempo más difícil de manejar la lista de ubicaciones alternativas que Google devuelve, y lo hizo con algunas variables globales funky, una función dentro de un bucle 998877766555444330 , y algunas otras prácticas de codificación. Esos son changeMapLocation() y buildAltLocationList() .

Todo funciona como lo quiero, pero este es un proyecto de aprendizaje. Apreciaría cualquier sugerencia para refactorizar, factores de diseño, mantenimiento, etc.

  /* Google Address to coordinates code from: http://krasimirtsonev.com/blog/article/GoogleMaps-JS-API-address-to-coordinates-transformation-text-to-LatLng */ (function () { // Begin scoping function     "use strict";     var map = null;     var returnedLocation;     var altLocationsList;     var isAlt = false;     var markersArray = [];       /*Initializing the map and input elements*/      window.onload = function () {         // initialize the map and set options         var mapHolder = document.getElementById("map-holder");         map = new google.maps.Map(             mapHolder,             {                 zoom: 3,                 mapTypeId: google.maps.MapTypeId.ROADMAP,                  zoomControl: true,                 zoomControlOptions: {                     style: google.maps.ZoomControlStyle.SMALL,                     position: google.maps.ControlPosition.RIGHT_TOP                 },                 panControl: true,                 panControlOptions: {                     position: google.maps.ControlPosition.TOP_RIGHT                 },                 streetViewControl: false             }         );          // centering the map         map.setCenter(new google.maps.LatLng(20.2, 0.1));          // Add event listeners          //Search field - button click          document.getElementById("search").onclick = function () {             var address = document.getElementById("searchtext").value;             addressToLocation(address, changeMapLocation);             isAlt = false;             clearResultsLaunchSpinner();         };          //Search field - hit enter           document.getElementById("searchtext").onkeydown = function (e) {             if (e.keyCode === 13) {                 var address = document.getElementById("searchtext").value;                 addressToLocation(address, changeMapLocation);                 isAlt = false;                 clearResultsLaunchSpinner();             }         };          document.getElementById("layer-toggle").onclick = function () {             toggleLayer(0);         };     };       function clearResultsLaunchSpinner () {         $(document.body).removeClass("showing-results");         document.getElementById("locationName").innerHTML="";         document.getElementById("zoneDescription").innerHTML="";         document.getElementById("zoneOutput").innerHTML="";         document.getElementById("numOfAlts").innerHTML="";         document.getElementById("altIds").innerHTML="";         clearOverlays();         $(document.body).addClass("active");     }      function clearOverlays() {         for (var i = 0; i < markersArray.length; i++ ) {             markersArray[i].setMap(null);         }             markersArray = [];     }      /*Zooming to location and passing reults to climate zone query*/      function changeMapLocation(locations) {         clearResultsLaunchSpinner();          // isAlt determine if this is inputed through the search field or clicked on in the list of alternates and called from buildAltLocationsList()          if(locations && locations.length && isAlt === false) {               //Set up a marker and pan map to our best location             var marker = new google.maps.Marker({                 map: map,                 position: locations[0].location             });             markersArray.push(marker);              returnedLocation = locations[0].text + "<br>(" + parseFloat(locations[0].location.k).toFixed(2) + ", " + parseFloat(locations[0].location.B).toFixed(2) + ")";             map.panTo(locations[0].location);             map.setZoom(6);             //send lat/lng pair to rounder             rounder([locations[0].location.k, locations[0].location.B]);                //Redfine global var so it can be used at the end of Climate Zone query to to call buildAltLocationsList()             altLocationsList = locations;          }           else if (isAlt === true) {             marker = new google.maps.Marker({                 map: map,                 position: locations.location             });             markersArray.push(marker);              returnedLocation = locations.text + "<br>(" + parseFloat(locations.location.k).toFixed(2) + ", " + parseFloat(locations.location.B).toFixed(2) + ")";             map.panTo(locations);             map.setZoom(6);             //send lat/lng pair to rounder             rounder([locations.location.k, locations.location.B]);           }         else {             describeClimatezone (null);         }      }      function buildAltLocationsList (locations) {         //Determine whether or not to include the "best result" in altLocationsList or not          var arrIndex;         if (isAlt === false ) {             arrIndex = 1;         }         else {             arrIndex = 0;         }          document.getElementById("altIds").innerHTML = "";          if (locations.length > 1) {             document.getElementById("numOfAlts").innerHTML = locations.length-arrIndex + " alternate locations found. Click to search:";              for(var i=arrIndex; i<locations.length; i++) {                   document.getElementById("altIds").innerHTML += "<li id = alt" + i + "><a>" + locations[i].text + "</a></li>";             }              //Separate for loop to build the click handler for each li             for(var z=arrIndex; z<locations.length; z++) {                   (function (z) {                     document.getElementById("alt" + z).onclick = function () {                         if (window.console.firebug !== undefined) {                             console.log(locations[z]);                         }                         else {                             isAlt = true;                             changeMapLocation(locations[z]);                         }                     };                 })(z);             } //End 2nd for loop         }                }       // Prepping data for Fusion Table Query.      // Everything has to be rounded to nearest .25 or .75 to match the data      function rounder (x) {         for (var i = 0; i < x.length; i++) {         var xDecimal = (x[i] % 1);             if (xDecimal >= 0 && xDecimal <= 0.5) {                 x[i] += (0.25 - xDecimal);             }              if (xDecimal > 0.5 && xDecimal < 1) {                 x[i] += (0.75 - xDecimal);             }             if (xDecimal >= -0.5 && xDecimal  < 0) {                  x[i] += (-0.25 - xDecimal);              }             if (xDecimal > -1.00 && xDecimal < -0.5) {                 x[i] += (-0.75 - xDecimal);            }         }        determineClimateZone(x[0], x[1]);     }      // Fusion Table Query of list of table of worldwide lat/lng pairs and their climate zone     // https://www.google.com/fusiontables/DataSource?docid=1GQfBT-PXojUbIZP7_tkILYKNjHaQjYqop9gkosho        function determineClimateZone(lat, lng) {        var query =    "SELECT 'Cls' FROM " +                        "1GQfBT-PXojUbIZP7_tkILYKNjHaQjYqop9gkosho" +                        " WHERE 'Lat' = '" + lat + "' AND Lon = '" + lng + "'";         var encodedQuery = encodeURIComponent(query);          // Construct the URL         var url = ["https://www.googleapis.com/fusiontables/v1/query"];         url.push("?sql=" + encodedQuery);         url.push("&key=AIzaSyAm9yWCV7JPCTHCJut8whOjARd7pwROFDQ");         url.push("&callback=?");          // Send the JSONP request using jQuery         $.ajax({           url: url.join(""),           dataType: "jsonp",           success: function (data) {             describeClimatezone(data.rows[0]);           }         });       }      function describeClimatezone (climateZone) {         var czArray = [             ["Af","Tropical rainforest"],             ["Am","Tropical monsoon"],             ["Aw","Tropical wet and dry or savanna"],             ["As","Tropical wet and dry or savanna ('summer' dry season)"],             ["BWh","Subtropical desert"],             ["BSh","Subtropical steppe"],             ["BWk","Mid-latitude desert"],             ["BSk","Mid-latitude steppe"],                      ["Csa","Mediterranean, hot summer"],              ["Csb","Mediterranean, warm summer"],                          ["Cfa","Humid subtropical, no dry season"],             ["Cwa","Humid subtropical, dry winter"],             ["Cwb","Temperate highland tropical climate with dry winters"],             ["Cwc","Temperate highland tropical climate with dry winters"],             ["Cfb","Marine west coast, warm summer"],             ["Cfc","Marine west coast, cool summer"],             ["Dfa","Humid continental, no dry season, hot summer"],             ["Dfb","Humid continental, no dry season, warm summer"],             ["Dwa","Humid continental, severe dry winter, hot summer"],             ["Dwb","Humid continental, severe dry winter, warm summer"],             ["Dsb","Humid continental, dry warm summer"],                              ["Dfc","Subartic, severe winter, no dry season, cool summer"],              ["Dfd","Subartic, severe very cold winter, no dry season, cool summer"],                          ["Dwc","Subartic, dry winter, cool summer"],             ["Dsc","Subartic, subalpine"],             ["Dwd","Subartic, very cold and dry winter, cool summer"],             ["ET","Tundra"],             ["EF","Ice Cap"]     ];         var zoneDescriptionText;          for (var i = 0; i < czArray.length; i++) {             if (climateZone == czArray[i][0]) {                 zoneDescriptionText = czArray[i][1];             }             else if (climateZone === null) {                 zoneDescriptionText = "Location Not Found! Look at an atlas!";             }         }          document.getElementById("locationName").innerHTML = "Showing Results for: <br>" + returnedLocation;         document.getElementById("zoneOutput").innerHTML = document.getElementById("zoneOutput").innerHTML + climateZone;         document.getElementById("zoneDescription").innerHTML = document.getElementById("zoneDescription").innerHTML + zoneDescriptionText;            //Change classes in DOM to hide spinner         $(document.body).removeClass("active");         $(document.body).addClass("showing-results");          //Now that the climate zone has been returned, call function to build a list of alternate locations returned by Google's Geocode         buildAltLocationsList(altLocationsList);      }      // converting the address's string to a google.maps.LatLng object     function addressToLocation(address, callback) {         var isAlt = false;         var geocoder = new google.maps.Geocoder();         geocoder.geocode(             {                 address: address             },              function(results, status) {                 var resultLocations = [];                  if(status == google.maps.GeocoderStatus.OK) {                     if(results) {                         var numOfResults = results.length;                         for(var i=0; i<numOfResults; i++) {                             var result = results[i];                             resultLocations.push(                                 {                                     text:result.formatted_address,                                     addressStr:result.formatted_address,                                     location:result.geometry.location,                                     lat:result.geometry.location.lat(),                                     lng:result.geometry.location.lng(),                                 }                             );                         }                     }                 } else if(status == google.maps.GeocoderStatus.ZERO_RESULTS) {                     // address not found                 }                  if(resultLocations.length > 0) {                     callback(resultLocations, false);                 } else {                     callback(null);                 }             }         );     }      //define layer      var layer = new google.maps.KmlLayer("https://sco-tt.github.io/What-s-My-Climate-Zone/Koeppen-Geiger-GE.kmz",     {preserveViewport: true});      //toggle kmz layer function      function toggleLayer() {         if(layer.getMap()===null) {             layer.setMap(map);             google.maps.event.trigger(map, "resize");             $("#layer-toggle").addClass("pure-button-active");         }         else {             layer.setMap(null);             $("#layer-toggle").removeClass("pure-button-active");          }     }     })();         // End scoping function   
Original en ingles

I'm trying to learn JavaScript, and as a practice tool I recently wrote a simple web app that uses the Google Maps API Geocoder to get the latitude and longitude of a location (user input), manipulate them, then query those against a Google Fusion Table listing the world's climate zone codes according to the Kxc3xb6ppen-Geiger climate classification. Basically people can type in a location and find out what climate zone it is, and see a map with the zones overlaid if they want it (might be of interest to geography buffs).

All of the logic is in a JavaScript file copied below. It was my goal to write as much of it without jQuery as possible, so I only use jQuery to handle the Fusion Tables request and to add/remove classes.

I've run it through JShint, and fixed most of the things mentioned there. I had the hardest time handling the list of alternative locations that Google returns, and did it with some funky global variables, a function within a for loop, and some other certainly coding practices. Those are changeMapLocation() and buildAltLocationList().

Everything works like I want it to, but this is a learning project I'd appreciate any suggestions for refactoring, design factors, maintainability, etc.

/* Google Address to coordinates code from: http://krasimirtsonev.com/blog/article/GoogleMaps-JS-API-address-to-coordinates-transformation-text-to-LatLng */ (function () { // Begin scoping function     "use strict";     var map = null;     var returnedLocation;     var altLocationsList;     var isAlt = false;     var markersArray = [];       /*Initializing the map and input elements*/      window.onload = function () {         // initialize the map and set options         var mapHolder = document.getElementById("map-holder");         map = new google.maps.Map(             mapHolder,             {                 zoom: 3,                 mapTypeId: google.maps.MapTypeId.ROADMAP,                  zoomControl: true,                 zoomControlOptions: {                     style: google.maps.ZoomControlStyle.SMALL,                     position: google.maps.ControlPosition.RIGHT_TOP                 },                 panControl: true,                 panControlOptions: {                     position: google.maps.ControlPosition.TOP_RIGHT                 },                 streetViewControl: false             }         );          // centering the map         map.setCenter(new google.maps.LatLng(20.2, 0.1));          // Add event listeners          //Search field - button click          document.getElementById("search").onclick = function () {             var address = document.getElementById("searchtext").value;             addressToLocation(address, changeMapLocation);             isAlt = false;             clearResultsLaunchSpinner();         };          //Search field - hit enter           document.getElementById("searchtext").onkeydown = function (e) {             if (e.keyCode === 13) {                 var address = document.getElementById("searchtext").value;                 addressToLocation(address, changeMapLocation);                 isAlt = false;                 clearResultsLaunchSpinner();             }         };          document.getElementById("layer-toggle").onclick = function () {             toggleLayer(0);         };     };       function clearResultsLaunchSpinner () {         $(document.body).removeClass("showing-results");         document.getElementById("locationName").innerHTML="";         document.getElementById("zoneDescription").innerHTML="";         document.getElementById("zoneOutput").innerHTML="";         document.getElementById("numOfAlts").innerHTML="";         document.getElementById("altIds").innerHTML="";         clearOverlays();         $(document.body).addClass("active");     }      function clearOverlays() {         for (var i = 0; i < markersArray.length; i++ ) {             markersArray[i].setMap(null);         }             markersArray = [];     }      /*Zooming to location and passing reults to climate zone query*/      function changeMapLocation(locations) {         clearResultsLaunchSpinner();          // isAlt determine if this is inputed through the search field or clicked on in the list of alternates and called from buildAltLocationsList()          if(locations && locations.length && isAlt === false) {               //Set up a marker and pan map to our best location             var marker = new google.maps.Marker({                 map: map,                 position: locations[0].location             });             markersArray.push(marker);              returnedLocation = locations[0].text + "<br>(" + parseFloat(locations[0].location.k).toFixed(2) + ", " + parseFloat(locations[0].location.B).toFixed(2) + ")";             map.panTo(locations[0].location);             map.setZoom(6);             //send lat/lng pair to rounder             rounder([locations[0].location.k, locations[0].location.B]);                //Redfine global var so it can be used at the end of Climate Zone query to to call buildAltLocationsList()             altLocationsList = locations;          }           else if (isAlt === true) {             marker = new google.maps.Marker({                 map: map,                 position: locations.location             });             markersArray.push(marker);              returnedLocation = locations.text + "<br>(" + parseFloat(locations.location.k).toFixed(2) + ", " + parseFloat(locations.location.B).toFixed(2) + ")";             map.panTo(locations);             map.setZoom(6);             //send lat/lng pair to rounder             rounder([locations.location.k, locations.location.B]);           }         else {             describeClimatezone (null);         }      }      function buildAltLocationsList (locations) {         //Determine whether or not to include the "best result" in altLocationsList or not          var arrIndex;         if (isAlt === false ) {             arrIndex = 1;         }         else {             arrIndex = 0;         }          document.getElementById("altIds").innerHTML = "";          if (locations.length > 1) {             document.getElementById("numOfAlts").innerHTML = locations.length-arrIndex + " alternate locations found. Click to search:";              for(var i=arrIndex; i<locations.length; i++) {                   document.getElementById("altIds").innerHTML += "<li id = alt" + i + "><a>" + locations[i].text + "</a></li>";             }              //Separate for loop to build the click handler for each li             for(var z=arrIndex; z<locations.length; z++) {                   (function (z) {                     document.getElementById("alt" + z).onclick = function () {                         if (window.console.firebug !== undefined) {                             console.log(locations[z]);                         }                         else {                             isAlt = true;                             changeMapLocation(locations[z]);                         }                     };                 })(z);             } //End 2nd for loop         }                }       // Prepping data for Fusion Table Query.      // Everything has to be rounded to nearest .25 or .75 to match the data      function rounder (x) {         for (var i = 0; i < x.length; i++) {         var xDecimal = (x[i] % 1);             if (xDecimal >= 0 && xDecimal <= 0.5) {                 x[i] += (0.25 - xDecimal);             }              if (xDecimal > 0.5 && xDecimal < 1) {                 x[i] += (0.75 - xDecimal);             }             if (xDecimal >= -0.5 && xDecimal  < 0) {                  x[i] += (-0.25 - xDecimal);              }             if (xDecimal > -1.00 && xDecimal < -0.5) {                 x[i] += (-0.75 - xDecimal);            }         }        determineClimateZone(x[0], x[1]);     }      // Fusion Table Query of list of table of worldwide lat/lng pairs and their climate zone     // https://www.google.com/fusiontables/DataSource?docid=1GQfBT-PXojUbIZP7_tkILYKNjHaQjYqop9gkosho        function determineClimateZone(lat, lng) {        var query =    "SELECT 'Cls' FROM " +                        "1GQfBT-PXojUbIZP7_tkILYKNjHaQjYqop9gkosho" +                        " WHERE 'Lat' = '" + lat + "' AND Lon = '" + lng + "'";         var encodedQuery = encodeURIComponent(query);          // Construct the URL         var url = ["https://www.googleapis.com/fusiontables/v1/query"];         url.push("?sql=" + encodedQuery);         url.push("&key=AIzaSyAm9yWCV7JPCTHCJut8whOjARd7pwROFDQ");         url.push("&callback=?");          // Send the JSONP request using jQuery         $.ajax({           url: url.join(""),           dataType: "jsonp",           success: function (data) {             describeClimatezone(data.rows[0]);           }         });       }      function describeClimatezone (climateZone) {         var czArray = [             ["Af","Tropical rainforest"],             ["Am","Tropical monsoon"],             ["Aw","Tropical wet and dry or savanna"],             ["As","Tropical wet and dry or savanna ('summer' dry season)"],             ["BWh","Subtropical desert"],             ["BSh","Subtropical steppe"],             ["BWk","Mid-latitude desert"],             ["BSk","Mid-latitude steppe"],                      ["Csa","Mediterranean, hot summer"],              ["Csb","Mediterranean, warm summer"],                          ["Cfa","Humid subtropical, no dry season"],             ["Cwa","Humid subtropical, dry winter"],             ["Cwb","Temperate highland tropical climate with dry winters"],             ["Cwc","Temperate highland tropical climate with dry winters"],             ["Cfb","Marine west coast, warm summer"],             ["Cfc","Marine west coast, cool summer"],             ["Dfa","Humid continental, no dry season, hot summer"],             ["Dfb","Humid continental, no dry season, warm summer"],             ["Dwa","Humid continental, severe dry winter, hot summer"],             ["Dwb","Humid continental, severe dry winter, warm summer"],             ["Dsb","Humid continental, dry warm summer"],                              ["Dfc","Subartic, severe winter, no dry season, cool summer"],              ["Dfd","Subartic, severe very cold winter, no dry season, cool summer"],                          ["Dwc","Subartic, dry winter, cool summer"],             ["Dsc","Subartic, subalpine"],             ["Dwd","Subartic, very cold and dry winter, cool summer"],             ["ET","Tundra"],             ["EF","Ice Cap"]     ];         var zoneDescriptionText;          for (var i = 0; i < czArray.length; i++) {             if (climateZone == czArray[i][0]) {                 zoneDescriptionText = czArray[i][1];             }             else if (climateZone === null) {                 zoneDescriptionText = "Location Not Found! Look at an atlas!";             }         }          document.getElementById("locationName").innerHTML = "Showing Results for: <br>" + returnedLocation;         document.getElementById("zoneOutput").innerHTML = document.getElementById("zoneOutput").innerHTML + climateZone;         document.getElementById("zoneDescription").innerHTML = document.getElementById("zoneDescription").innerHTML + zoneDescriptionText;            //Change classes in DOM to hide spinner         $(document.body).removeClass("active");         $(document.body).addClass("showing-results");          //Now that the climate zone has been returned, call function to build a list of alternate locations returned by Google's Geocode         buildAltLocationsList(altLocationsList);      }      // converting the address's string to a google.maps.LatLng object     function addressToLocation(address, callback) {         var isAlt = false;         var geocoder = new google.maps.Geocoder();         geocoder.geocode(             {                 address: address             },              function(results, status) {                 var resultLocations = [];                  if(status == google.maps.GeocoderStatus.OK) {                     if(results) {                         var numOfResults = results.length;                         for(var i=0; i<numOfResults; i++) {                             var result = results[i];                             resultLocations.push(                                 {                                     text:result.formatted_address,                                     addressStr:result.formatted_address,                                     location:result.geometry.location,                                     lat:result.geometry.location.lat(),                                     lng:result.geometry.location.lng(),                                 }                             );                         }                     }                 } else if(status == google.maps.GeocoderStatus.ZERO_RESULTS) {                     // address not found                 }                  if(resultLocations.length > 0) {                     callback(resultLocations, false);                 } else {                     callback(null);                 }             }         );     }      //define layer      var layer = new google.maps.KmlLayer("https://sco-tt.github.io/What-s-My-Climate-Zone/Koeppen-Geiger-GE.kmz",     {preserveViewport: true});      //toggle kmz layer function      function toggleLayer() {         if(layer.getMap()===null) {             layer.setMap(map);             google.maps.event.trigger(map, "resize");             $("#layer-toggle").addClass("pure-button-active");         }         else {             layer.setMap(null);             $("#layer-toggle").removeClass("pure-button-active");          }     }     })();         // End scoping function 
           
   
   

Lista de respuestas

3
 
vote

de una vez sobre: ​​

  • me gusta 'use strict';
  • tienes algunas constantes mágicas
    • zoom: 3, & lt; ¿Qué significa 3? Las constantes bien nombradas ayudarían al lector
    • new google.maps.LatLng(20.2, 0.1) & lt; - curioso ..
  • Considere addEventListener o JQUYERYEVENT MANIFICACIÓN En lugar de asignar oyente directamente como aquí:
    document.getElementById("search").onclick & lt; - Esto no juega bien
  • en mi mente, si usa jQuery en todo lo que debe buscar elementos. document.getElementById("search") & LT; & GT; .ToList()0
  • Las nuevas recién llegadas para separar el código podrían estar en la parte superior, me apegaría a las nuevas recién llegadas
  • Escribiría lo siguiente con un ternario:

      .ToList()1  

    podría ser

      .ToList()2  
  • su .ToList()3 Llamadas .ToList()4 , que no debe ser el trabajo de .ToList()5
  • Hubiera llamado .ToList()6 .ToList()7
  • Jugaría con tener 1 función para establecer .ToList()8 , 99887766555443319 En lugar de 2, ahora está mezclando la interfaz de usuario y el modelo en GetValueOrDefault()0
  • Desde un nivel mucho más alto, si alguna vez su tabla de búsqueda cambia de redondeo a GetValueOrDefault()1 y GetValueOrDefault()2 (que es una opción tan extraña, por lo que parece probable que suceda) , entonces su código está roto. Pasaría algún tiempo para analizar la tabla de fusión y encontrar la entrada correcta independiente de las opciones de redondeo.
 

From a once over:

  • I like 'use strict';
  • You have a few magic constants
    • zoom: 3, <- What does 3 mean ? Well named constants would help the reader
    • new google.maps.LatLng(20.2, 0.1) <- Curious..
  • Consider addEventListener or jQueryevent handling instead of assigning listener directly like here:
    document.getElementById("search").onclick <- This does not play nice
  • In my mind, if you use jQuery at all you should it for looking up elements. document.getElementById("search") <> $("#search")
  • Double newlines to separate code might be over the top, I would stick to single newlines
  • I would write the following with a ternary:

    var arrIndex; if (isAlt === false ) {     arrIndex = 1; } else {     arrIndex = 0; } 

    could be

    var arrIndex = isAlt?0:1; 
  • Your rounder calls determineClimateZone, that should not be the job of rounder
  • I would have called rounder roundCoordinates
  • I would play around with having 1 function to set locationName, zoneDescription instead of 2, you are now mixing UI and model in describeClimatezone
  • From a much higher level, if ever your lookup table changes from rounding to .25 and .75 (which is such a weird choice, so it seems likely to happen), then your code is broken. I would spend some time to analyze the fusion table and find the correct entry independent of rounding choices.
 
 
 
 

Relacionados problema

22  Inicializador Simple Async Google Maps con angularjs  ( Simple async google maps initializer with angularjs ) 
Aquí está un simple reutilizable 9988776655544337 factory Me acompañé para inicializar los mapas de Google de forma asíncrona, lo que de alguna manera no ...

6  Código postal a la ciudad, estado de estado de registro  ( Zip code to city state for registration form ) 
me tomó un par de días ( entre trabajar en otros proyectos ) para que el código funcione, pero ahora que lo tengo trabajando, me gustaría saber si hay una man...

3  Bucle a través de las consultas de parse.com  ( Looping through parse com queries ) 
Aquí está mi archivo JavaScript que consulta datos de Parse y luego actualiza la plantilla de My Mandenbars.js para mostrarlos. El código tiene 3 llamadas de ...

2  Dirección Geocoder  ( Address geocoder ) 
Si lo observa, hay variables de street_address , 99887766555443310 , 99887766555443311 reutilizado en toda la base de código. En realidad, son de los comp...

2  Añadiendo pasadores a un mapa de google  ( Adding pins onto a google map ) 
Tengo el siguiente bloque de código que agrega pasadores, incluidas las descripciones y los enlaces a un mapa de Google. ¿Cómo puedo refactarlo para que pueda...

7  Diagrama de Voronoi esférico, enfoque de división binario [cerrado]  ( Spherical voronoi diagram binary splitting approach ) 
cerrado. Esta pregunta es off-topic . Actualmente no está aceptando respuestas. ¿Quieres ...

2  Agregar eventos a múltiples marcadores en un mapa de Google  ( Adding events to multiple markers in a google map ) 
Estaba mirando las preguntas relacionadas con la configuración de marcadores en un mapa de Google, y aunque las siguientes funcionan perfectamente bien para m...

7  Excel VBA para analizar JSON fuera de Google Maps API  ( Excel vba to parse json out of google maps api ) 
Algún código que escribí y rompí en 5 preguntas separadas en el desbordamiento de la pila. Algún tipo quería consultar a Google Maps recibir un poco de JSON y...

1  Un complemento ETA para HANGOUTSBOT  ( An eta plugin for hangoutsbot ) 
Este es un complemento para Hangoutsbot / HoodOutsBot que escucha las palabras que la gente dice y luego les da una ETA y un enlace con direcciones. Feliz...

2  Visualización de múltiples marcadores de Google Maps en una página de VisualForce  ( Displaying multiple google maps markers on a visualforce page ) 
Espero que este sea el tablero correcto para esto. Soy un programador novato y estoy tratando de aprender a escribir un mejor código. Tengo una página de Visu...




© 2022 respuesta.top Reservados todos los derechos. Centro de preguntas y respuestas reservados todos los derechos