Geolocation and jQuery - Can't post results using ajax

Posted by etombaugh on Stack Overflow See other posts from Stack Overflow or by etombaugh
Published on 2011-10-17T17:21:11Z Indexed on 2012/06/01 10:40 UTC
Read the original article Hit count: 276

I'm currently working on a project to make a location-aware site. In essence, the user comes to the page, and their location is found using the HTML5 method and then using jQuery, the location is posted to a page which saves the location/address to a codeigniter session, but if they want to update their location, or change to a different location(IE they want to use their work address as the location instead of their present address), theres a jQuery colorbox that displays and lets them type in a custom address.

Everything works flawlessly to get the initial location, but when I try and get the updated location saved, I receive the error "Uncaught TypeError: Object [object DOMWindow] has no method 'lat'" which then Google Chrome references as being an error not in jQuery, but in the file for Google Maps API. Any suggestions?

jQuery('.inputsubmit').click(function() {

//Takes values from user submitted fields and parses them into an address string
var street = jQuery('.inputaddress').val();
var city = jQuery('.inputcity').val();
var state = jQuery('.inputstate').val();


var address = street +" "+ city +", " +state;

   geocoder = new google.maps.Geocoder();
   var geocoderresult= geocoder.geocode({'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
           var newlocation = results[0].geometry.location;

               //Posts coordinates and address string to a CodeIgniter function to update users session information
               jQuery.post("somepage", {location: newlocation, address: address},function(data) {
             alert("Data Loaded: " + data);
           });

       } else {
          alert("Geocoder failed due to: " + status);
       }
    });

});

I've tried everything I can think of to get the post to work. All of the code works up till the point, and I've commented out the post line and everything works correctly. This is one of our main website's features, to provide instant and quick results based off of location.

Thanks!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX