My First Google Map - Chicago Elementary schools

Published Tuesday, October 23, 2007 7:00 PM

Dispite my negetive feelings about Google Map API, I still rushed to set up a website and created a bunch of rudimentary Google maps, out of the urgent need to jump on the Google broadwagen and real practical reasons. I have a little girl who is four and who will go to kindergarten next year, so I am trying all my might to find a good school for her. So as a web techie and a mom, I had to search low and high and map out all the options.

So much for the small talk. Here is the map of Chicago Elementary Schools. And the url is http://www.codexd.info/googlemaps/chicagoschools.htm

Map of Chicago Elementary Schools

There are a few functions worth noting:

1) GDownloadUrl

I use the function to dynamically loaded chicago schools data and in the same time, passed as literal the function to process it and add the points to the map. As the following

/load chicago school data

GDownloadUrl("schools.txt", process_it);

// === Define the function thats going to process the text file ===

process_it = function(doc, responseCode) {

// To ensure against HTTP errors that result in null or bad data,

// always check status code is equal to 200 before processing the data

if(responseCode == 200) {

// === split the document into lines ===

var lines = doc.split("\n");

// lines.sort();

var parts;

var schoolList=document.forms[0].schoolList;

for (var i=1; i<lines.length; i++) {

//only elementary schools

if (lines[i].length > 1 && lines[i].indexOf("ELEM")>0) {

 

 

parts = lines[i].split(
",");

var lat = parseFloat(parts[4]);

var lng = parseFloat(parts[3]);

 

//var html = "To be added";

var label = parts[0];

 

// Add option to the bottom of the list

schoolList[schoolList.length] = new Option(label, lat + "," + lng);

// alert( label + " " + lat + " " + lng);

var point = new GLatLng(lat,lng);var marker = createLabelMarker(point, label, "Coming Soon");

map.addOverlay(marker);

bounds.extend(point);

centerMap(i);

}

}

}

else if(responseCode == -1) {

alert("Data request timed out. Please try later.");

} else { alert("Request resulted in error. Check XML file is retrievable.");

}

}

The process_it is an umbralla function that has covered layers of operations and procedures. First, it checks to ensure the httprequest for remote data has a valid return; then it parses the comma delimited text file into seperate fields and take in information such as lat, lon, school name, etc.; then it creates map markers and adds it to the basemap; and point by point, it expands the map extent and adjust the map center and zoom level. 

Isn't it confusing? Deep breath.

I stole this function for centering and zooming a map dynamically by addresses.

function centerAndZoomOnBounds(bounds){

var center = bounds.getCenter();

var newZoom = map.getBoundsZoomLevel(bounds);if (map.getZoom() != newZoom){

map.setCenter(center, newZoom);

}
else{

map.panTo(center);

}

}

 This map also includes a function for local search. And the search function is directly lifted out of the Google Map API website. The local search takes three steps, first, get the address being searched; second call the Geocoder to get the lat, and lon; third, locate the address on the map.

function showLocation() {var address = document.forms[0].q.value;

geocoder.getLocations(address, addAddressToMap);

}

// findLocation() is used to enter the sample addresses into the form.

function findLocation(address) {

document.forms[0].q.value = address;

showLocation();

}

Later, I hope my maps will go beyond and deeper.

 

by xxxd
Filed under:

Comments

#   My First Google Map - Chicago Elementary schools by planetsq said on Sunday, November 25, 2007 9:31 AM

Pingback from  &nbsp; My First Google Map - Chicago Elementary schools&nbsp;by&nbsp;planetsq

# http://dotnetslackers.com/community/blogs/xun/archive/2007/10/23/my-first-google-map-chicago-elementary-schools.aspx said on Tuesday, March 25, 2008 4:27 AM

Pingback from  dotnetslackers.com/.../my-first-google-map-chicago-elementary-schools.aspx

This site

This Blog

Syndication

Sponsors

  • MaximumASP
  • Social Bookmarking
    Online Shopping
    asp.net hosting
    UK online local dating