【问题标题】:How to get lat/lng from a geo-autocomplete object and google api V2?如何从地理自动完成对象和 google api V2 中获取 lat/lng?
【发布时间】:2011-07-08 11:21:30
【问题描述】:

我正在尝试使用 jQuery、jquery.autocomplete_geomod 和 geo_autocomplete 插件以及 Google Maps API V2 来实现地理自动完成。

同时,我们正在迁移到 V3,所以不要害怕说我的问题是由于版本 2。

所以,我需要自动完成返回的纬度/经度,将我的地图集中在这个坐标上......但我没有成功!

我的代码有一部分。不要犹豫,问我问题。

$().ready(function() {

    var mygc = new google.maps.Geocoder();

    var loc = $('#location').geo_autocomplete(mygc, {
        mapkey: '<?$GOOGLE_KEY?>',
        ...
        geocoder_address: true

      }).result(function(_event, _data){
         //if(_data){
                    alert("test");
                    alert( "latitude : " + results[0].geometry.location.lat() );
          //}
                   //alert( "longitude : " + results[0].geometry.location.lng() );
        });

    });

问候,

来自法国的纪尧姆

【问题讨论】:

    标签: autocomplete geocoding google-maps-api-2


    【解决方案1】:

    ui.geo_autocomplete.js 中,将位置变量_location = _result.geometry.location 添加到_parsed 结果中。

    类似这样的:

    _parsed.push({
        value: _place,
        label: _result.formatted_address,
        viewport: _result.geometry.viewport,
        location: _location
    });
    

    然后你可以从_ui.item.geometry.location访问它。

    【讨论】:

      【解决方案2】:

      在第 73 行将ui.geo_autocomplete.js 扩展为location: _result.geometry.location

      _parsed.push({
      value: _place,
      label: _result.formatted_address,
      viewport: _result.geometry.viewport,
      location: _result.geometry.location
       });
      

      您可以使用 alert() 方法访问这些变量,例如:

      $('#stadt').geo_autocomplete({
          geocoder_region: 'Germany',
          geocoder_types: "locality,political,sublocality,neighborhood",
          mapheight: 100, mapwidth: 200, maptype: 'hybrid',
           select: function(event, ui) {
          alert(ui.item.location);
          return false;
      }
      
      })
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-14
        • 1970-01-01
        • 1970-01-01
        • 2022-01-02
        • 2013-03-23
        • 2018-08-14
        相关资源
        最近更新 更多