【问题标题】:Allow users to manualy overide geolocation允许用户手动覆盖地理位置
【发布时间】:2012-04-17 10:11:48
【问题描述】:

我一直在寻找一种方法来允许用户手动覆盖网站上的地理位置(以防它不正确)。

感谢任何抽出时间回复我的帖子的人已经在谷歌上搜索了分配但没有任何进展。

【问题讨论】:

    标签: php jquery mysql geolocation geo


    【解决方案1】:

    添加一个文本框供用户输入他们的位置。然后将其提交给地理编码 API 服务,例如 Google Maps、geocoding.us、Yahoo Maps 等。返回并在您的应用程序中使用该结果。

    如果您使用 Google Maps API,则对地址进行地理编码非常简单。 address 是用户输入街道地址的文本字段。 latlng 是一个文本字段,用于保存输出的纬度/经度。

    $('#searchButton').click(function() {
      var geocoder = new google.maps.Geocoder();
      geocoder.geocode( {'address': $('#address').val() }, function(data, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          $('#latlng').val(data[0].geometry.location.lat+", "+data[0].geometry.location.lng);
        else {
          alert("Geocode was not successful for the following reason: " + status);
        }
      });
      return false;
    });
    

    https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-simple

    【讨论】:

    • 感谢您的回答,无论如何您都可以展示如何执行此操作的示例代码,非常感谢。
    • 嘿,感谢您的示例并花时间回复我必须等待 4 分钟才能单击答案旁边的勾号!整天都在寻找这样的例子!
    猜你喜欢
    • 2021-08-30
    • 1970-01-01
    • 2013-11-26
    • 2019-01-07
    • 2010-12-20
    • 2011-11-25
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多