Im trying to add reverse geocoding compatability to the Gmap and Location form. I found a post that turned an address into a marker in a Gmap, but now I want to take info from the Gmap and add it to the Location Form. I have the code to turn a point on a Gmap into an address, I just need help on how to modify these modules. I have only been using drupal for about a week.

Basically I want to add a "Gevent.addListener" to the map, which I do not knw how to do with the Gmap module.

Then I will turn the geocoded point into an address then add the Gmarker to the map and populate the Location form with the address.

I just need to know where to put the code. Any help would be great.

Thanks.

Comments

summit’s picture

Hi,

It could help if you distribute the code, what you have until now.
Greetings,
Martijn

cday119’s picture

Here is my modified location_module. Its a modified version of the location/GMap combo. I have been developing for many years but do not really yet know how to best implement this code into drupal. Any suggestions would greatly help. I threw this together in a few hours so its pretty sloppy. The end of the file is the reverse geocoder functions. You also need the CURL_Request.php file to do requests to geonames.com to do xml requests.

Basically I dont know where to put a GEvent.AddListener for just the map in the location submission form and not every map on a site. And the best way to add the XML data to the location form.

function reverseGeocode(lat, lng) {
    var request = GXmlHttp.create();
    request.open("GET", "/sites/all/modules/map_location_5/CURL_Request.php?lat=" + lat + "&lng=" + lng, true);
    request.onreadystatechange = function () {
      if (request.readyState == 4){ 
        var xmlDoc = request.responseXML;
        var address = xmlDoc.documentElement.getElementsByTagName("address");
        displayAddress(address[0]);
      }
    };
    request.send(null);
  }

function displayAddress(address) {
  var street = address.getElementsByTagName("street")[0].childNodes[0].nodeValue;
  var number = address.getElementsByTagName("streetNumber")[0].childNodes[0].nodeValue;
  document.getElementById("edit-locations-0-street").value = number + " " + street;
  var city = address.getElementsByTagName("placename")[0].childNodes[0].nodeValue;
  document.getElementById("edit-locations-0-city").value = city;
  var state = address.getElementsByTagName("adminCode1")[0].childNodes[0].nodeValue;
  document.getElementById("edit-locations-0-province").value = "us-" + state;
  var postalcode = address.getElementsByTagName("postalcode")[0].childNodes[0].nodeValue;
  document.getElementById("edit-locations-0-postal-code").value = postalcode;
  

}

pkej’s picture

Subscribe.

Paul K Egell-Johnsen

Paul K Egell-Johnsen

Wouter Van den Bosch’s picture

Subscribing.

socialnicheguru’s picture

subscribing

http://SocialNicheGuru.com
Delivering inSITE(TM), we empower you to deliver the right product and the right message to the right NICHE at the right time across all product, marketing, and sales channels.