Source Code for JavaScript Mapping Tools: geoCode.js

Source code of a graphical tool for drawing and computing distances over Google maps.

Run Tool | index.html | main.css | formatters.js | geoCircle.js | geoCode.js | geo.js | index.js | mapControls.js | tableManager.js | util.js | wayPoint.js | wayPointsManager.js


// Copyright 2006-2008 (c) Paul Demers  <paul@acscdg.com>

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA., or visit one 
// of the links here:
//  http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
//  http://www.acscdg.com/LICENSE.txt

//////////////////////////////////////////////////////////////////

// Map drawing and distance tools.

//
// JavaScript objects that work with the Google geocoder object.
// Web site with this code running: http://www.acscdg.com/
//

//
//
//// Dependencies:
// _map from index.js
// Google maps for geocode and geopoint.

var _geocoder;  // The geocoder is only created once.
var _addressToGeoCode;  // Save the address, for the error message.

//
//// Called from the Google geocode when it is done.
function foundLocation(response)
{
  if ((response == null) || (response.Status.code != G_GEO_SUCCESS))
  {
    alert("\"" + _addressToGeoCode + "\" not found");
  }
  else
  {
    var place = response.Placemark[0];
    var point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
    _map.setCenter(point);
    var marker = new GMarker(point, {title: place.address} );
    _map.addOverlay(marker);
    marker.openInfoWindowHtml(place.address);

    GEvent.trigger(_map, "click", marker, point);  // Generate a click at this point,
                                                   //  which adds the point to the current course.
  }
}


//
//// Called when the "Find" button is pushed.
//// Reads the place name from the form, then calls the geocoder. 
function findLocation() {
  _addressToGeoCode = document.forms[0].q.value;
  _geocoder.getLocations(_addressToGeoCode, foundLocation);
}


//
//// Create and cache the Google geocoder object.
//// caller must destroy _geocoder when no longer needed.
function initGeoCoder()
{
  _geocoder = new GClientGeocoder();
}


//// End of geocoding.
//