0

I am working on Geocoding a city/country input value using Javascript which is a result of another JS function. The function that inputs the result to the value is called sata() and the Google Geocode function is called UpdateMap(), which prints out a latitude and longitude in two different inputs. I do need some help to get this working. I tried using some event listeners but so far it hasn't worked, unless I'm not doing it correctly.

JS to combine two inputs to one city, country for input value id "refcity"

  function sata() 
   { 
     var atjat = document.getElementById("piprovincia").value; 
     document.getElementById("refpro").value = atjat; 
      var atjob = document.getElementById("slct2").value; 
     document.getElementById("refcity").value = atjob;  

     var allja = atjob + ', '+ atjat; 
     document.getElementById("jobadder").value = allja; 
   } 

JS to convert city, country input "jobadder" to latitude/longitude. I tried using onchange with the input, which doesn't work.

 // Update the Google map for the user's inputted address
function UpdateMap()
{ 
   var geocoder = new google.maps.Geocoder();    // instantiate a geocoder object
    // Get the user's inputted address
    var address = document.getElementById("jobadder").value;

    // Make asynchronous call to Google geocoding API
    geocoder.geocode( {'jobadder': address}, function(results, status) {
        var addr_type = results[0].types[0];    // type of address inputted that was geocoded
        if ( status == google.maps.GeocoderStatus.OK )
        { 
             var location = results[0].geometry.location,
        lat      = location.lat(),
        lng      = location.lng();

         document.getElementById("test1").value = lat;
         document.getElementById("test2").value = lng; 
        } 
        else    
        {   
            alert("Geocode was not successful for the following reason: " + status);     
        } 
    });
}
Jeffrey Teruel
  • 364
  • 2
  • 10
  • 29
  • Can you add a parameter to the UpdateMap function and simply pass it "allja" when you would like it updated instead of monitoring "jobadder"? – Corey Hoffman May 22 '15 at 15:52
  • Try UpdateMap() using constants for address and see if it works. Then I would put UpdateMap() inside sata() as the last line to test it. Make sure each of your functions work with constants instead of variables first. – so_jin_ee May 22 '15 at 17:45

0 Answers0