地理定位和 jQuery - 无法使用 ajax 发布结果

发布于 2024-12-10 12:44:54 字数 1433 浏览 0 评论 0原文

我目前正在开发一个项目来制作一个位置感知网站。本质上,用户来到该页面,使用 HTML5 方法找到他们的位置,然后使用 jQuery,将该位置发布到一个页面,该页面将位置/地址保存到 codeigniter 会话中,但如果他们想要更新其位置,或更改为不同的位置(即他们想要使用他们的工作地址作为位置而不是他们现在的地址),有一个 jQuery 颜色框可以显示并让他们输入自定义地址。

一切都完美地获取初始位置,但是当我尝试保存更新的位置时,我收到错误“Uncaught TypeError: Object [object DOMWindow] has no method 'lat'”,然后 Google Chrome 引用的错误不是在 jQuery 中,而是在 Google Maps API 文件中。有什么建议吗?

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'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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房的律动 2024-12-17 12:44:54

我认为除了原始页面之外,您还需要将 Google API 代码加载到 somepage 上。由于 $.POST 找不到 lat 对象,因此 geolocation.js 文件似乎未包含在 somepage 中。

i think you need to have your Google API code loaded on somepage in addition the original page . Because the $.POST can't find the lat object it seems the geolocation.js file isn't included on somepage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文