Javascript – Google Geocode via HTTP callback function


I want to use the google geocode via HTTP functionality to translate a city name into longitude and latitude in for my AJAX web application.

However, it appears that no callback function exists for the HTTP geocoder functionality

Is that true, no callback function exists?

Because if that is true, it essentially means that the Google geocode via HTTP api is useless when used with AJAX because JavaScript will throw a crossdomain exception error.

Any ideas on how I can use the geocode via HTTP api in my AJAX web application in JavaScript?

Note: I do not want to use the full blown Google Maps API which is approx 200kb download (i.e. GClientGeocoder). I want to use the HTTP api b/c of it's super quick responsiveness and lack of needing my web users from having to download the huge full blown interactive google maps api.



Best Solution

Here is an example that uses the Google Maps Geocoder. The geocoder function getLocation takes a callback function as the second argument.

function findAddress(street, city, state, zip) {
  var address = [
  ].join(', ');

  if (!geocoder) {
    geocoder = new GClientGeocoder();

  if (geocoder) {
      function(result) {
        var dialog, len, point;
        if (result.Status.code != G_GEO_SUCCESS) {
          alert("Error: "+result.Status.code)
        } else {
          len = result.Placemark.length;
          if (len > 1) {
            alert("Multiple matches were found.  I'll leave it as an exercise to handle this condition");
          } else {
            point = new GLatLng(