Saturday, September 27, 2008

JavaScript: Using Google Maps to find a location

You can use Google Maps service to find a location, for example a street address. In this example we create a web page with a text field and a button to find a location based on a street address. We create a small JavaScript program to use Google Maps in a new window to show the entered location on the map. See the example running here.

Create a new HTML file using your text editor. Place a form on the page as in listing 1. On the form there will be a text field and a button.

Listing 1. The form code. Click on the picture to see it in it's original size.



Next, add a script block in the header section of the document. See listing 2.

Listing 2. The JavaScipt block and code. Click on the picture to see it in it's original size.



Save the file. Open the page in your browser. Enter a location in the address field, for example Mannerheimintie 1, 00100 Helsinki, and hit the find button. The location should now be opened in a new window on the Google Maps.

No comments: