Mostrando entradas con la etiqueta javascript. Mostrar todas las entradas
Mostrando entradas con la etiqueta javascript. Mostrar todas las entradas

lunes, 10 de marzo de 2008

La importancia de los code reviews

Las consecuencias de no hacer una revisión de código pueden llegar a ser muy graves, incluso originar una catástrofe. Lo menos grave que puede pasar es que tu código se convierta en un hazme reir. Y es lo que ayer se podía ver en el código que genera parte de la página con los resultados electorales en la web del Ministerio del Interior. La página utiliza este archivo javascript que contiene, entre otras cosas lo siguiente:

inicializa: function (opt_doc) {
//alert('holaaaaaaaaaaaaaaa');
doc=opt_doc;
Muy profesional ¿verdad?

miércoles, 5 de marzo de 2008

My first PHP/MySQL/AJAX application

This post is intended to serve as a start point to others who have interest in developing their first GoogleMaps application using PHP/MySQL, to those who enjoy reading about this stuff just for fun and to those who don't have a clue about what these acronyms mean but perhaps would like to get into it after you've seen the result. The idea is to follow the design proposed here by Pamela Fox.

Requirements:

  • Apache, PHP5, MySQL
  • Basic knowledge about Javascript and XML
  • Google Maps API key (you can get one here with a Google Account)
How To:
  • Step 1. Populate your database with data. There are several ways to do this. I chose to manually introduce 4 sample rows with phpmyadmin. You can populate the database with the data that you like but don't forget to reserve two fields (type float) for the latitude and longitude:
database sample entries
  • Step 2. Output XML. In this part is where your PHP code has to query the database, extract the data and generate an XML output that the XMLHttpRequest can access later on from your main page. It's important that you keep your username, password and database name on a different file (dbinfo.php):
dbinfo.php

In order to query the database we just need to open a connection and run our query (xmlGenerator.php part 1):

xmlGenerator.php (I)

Yet, the xml output has to be generated and that is done by making use of the dom functions (xmlGenerator.php part 2):

xmlGenerator.php (2)

  • Step 3. Now, all that's left is to load the markers in a Google map. If you are new to the Google Maps API, take a look at "The Hello World of Google Maps". Once we have our Google Maps API key for our URL, all we need to do is to load the map and the markers. This is done by the GDownloadUrl function, which is the wrapper of the XMLHttpRequest. The design of the main HTML page is left for the reader. The only two javascript functions used in the creation of the map are as follow:
load function

createMarker function

Finally, the part from which the load function is called:

Before the display of the markers, remember to store all marker information in the database, In this case, for the display of a picture, html code was stored previously in a VARCHAR field in the database. The result of all looks like this:


Precautions and Tips:
  • Make sure you are using PHP5 and not PHP4 and that you don't have the domxml library activated on the php.ini file, since this could cause some incompatibility problems while trying to output data in XML. PHP5 has a dom library already built in and you shouldn't have to worry about anything if you intend to generate the XML data the way it was explained here.
  • If you want to deploy your application in your machine, just type http://localhost/ in the signup page for a Google Maps API key (stupid but it works).
Sources for this post:

Google Code FAQ - Using PHP/MySQL with Google Maps
Using PHP 5's DOM functions to create XML files from SQL data
Google Maps API

martes, 29 de enero de 2008

Modesta expansión de idioma

Lo primero de todo, disculpen las molestias si hoy han sufrido los tests que he llevado a cabo en el blog. Desde hace días quiero empezar a escribir en inglés y quizá también en alemán con el tiempo. Dentro de lo que blogger permite, tenía dos opciones, o bien traducir algunos posts y colocarles un link que llevara el uno al otro en caso de querer leer el post en el otro idioma, o bien, utilizar los tags para sacar un segmento llamado "English". La que requiere menos esfuerzo a la larga es la solución de los tags. Sin embargo, había que tener cuidado con una cosa. Con el tiempo, quedaría un pegote con la palabra English de tamaño descomunal en la nube de tags y eso no debería ocurrir ya que English no es realmente un tag que clasifique un contenido, sino simple metainformación (un meta-tag). Así que he modificado el código javascript de la nube de tags para que obvie las ocurrencias de English.

P.D.1 Por cierto, en el post del estreno del blog di un enlace para que Vds. pudieran insertar su nube de tags. Me parece mucho mejor lo que nos ofrecen en Tensaiweb: una herramienta con nos genera el código con los parámetros que deseemos para el color, tamaño, etc.

P.D.2 Por supuesto, insertar enlaces para traducir la página con Babelfish o Google nunca fue una opción.