Tag: google geocoder

Google GeoCode自动填充限制状态

我正在尝试在表单中添加Google Geocode自动填充字段。 我已经能够限制返回到国家(AU)的结果,但如果我可以将结果限制到州,那就更好了。 (新南威尔士/新南威尔士州) 这是我当前的initialize()函数: function initialize() { var options = { types: [‘geocode’], componentRestrictions: {country:”AU”} }; autocomplete = new google.maps.places.Autocomplete( (document.getElementById(‘autocomplete’)),options); google.maps.event.addListener(autocomplete, ‘place_changed’, function() { fillInAddress(); }); } 我已阅读文档,发现您可以使用types参数来限制结果,但我无法弄清楚确切的代码应该是什么。 只需将其更改为: types: [‘administrative_area1′:’NSW’], // OR ‘New South Wales’ 和以上类似的各种组合(=代替:等)没有奏效.. 有人能指出我正确的方向,实际的语法是我想要实现的目标吗? 谢谢。

Google Maps Geocoder:返回postal_code

我正在使用Jquery UI使用Google Maps Geocoder自动完成对地址的搜索,当选择地址时,它会返回地理编码信息。 这是片段: $(‘#address-dropdown’).autocomplete({ //Use geocoder to fetch lat+long values from an address input using google maps API source: function(request, response) { geocoder.geocode( {‘address’: request.term }, function(results, status) { response($.map(results, function(item) { return { label: item.formatted_address, value: item.formatted_address, location: item.geometry.location, latitude: item.geometry.location.lat(), longitude: item.geometry.location.lng() } })); }) }, 我需要能够返回用途“postal_code”来检查它们是否存在于允许的区域内。 以下是一个示例输出: http : //maps.googleapis.com/maps/api/geocode/json?address […]

从Google Maps Geocoder v3返回地址

我有以下function: $(function() { var address = $(“#address”).text(); var r; function encodeAddress() { geocoder = new google.maps.Geocoder(); geocoder.geocode({‘address’ : address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { results[0].geometry.location r = results[0].geometry.location console.log(“inside:” + r); } else { alert(“Google Maps had some trouble finding” + address + status); } }); } encodeAddress() console.log(“outside:” + r); }); […]

Google Geocoder异步问题

我相信我遇到了地理编码器结果的时间问题。 请参阅下面的代码片段。 我基本上执行地理编码并获得结果。 然后我通过jQuery AJAX调用将结果传递给服务器端方法。 最后,该方法的结果返回一个JSON对象。 根据结果​​,我可能会或可能不会执行第二个地理编码。 这就是问题所在。 您可以看到我将变量hasResult默认为false,并在确定有效结果时切换为true。 在所有情况下,这都是完美的,除非需要第二个地理编码。 地理编码成功发生并且代码执行,但最终的hasResult检查仍然返回false。 怎么会这样? var hasResult = false; geocoder.geocode({ “address”: address }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { $.ajax({ url: “URL”, type: “POST”, dataType: “json”, data: results contentType: “application/json; charset=utf-8”, success: function (result) { if (result.Valid) { hasResult = false; //Some other code, works […]

Google将地理编码API V3映射为不返回javascript函数的结果

我正在尝试使用Google地理编码器API V3根据用户指定的地址在地图上绘制位置,代码如下。 当我直接提出请求时(例如http://maps.googleapis.com/maps/api/geocode/json?address=peterborough&sensor=false ),我得到了预期的回复。 但是,当我使用下面的代码发出相同的请求时,在getLatLong函数退出后, 中点变量始终未定义。 我做错了什么? function loadFromSearch(address) { midpoint = getLatLong(address); mapCentre = midpoint; map.setMapTypeId(google.maps.MapTypeId.ROADMAP); … } function getLatLong(address) { var result; var url = ‘http://maps.googleapis.com/maps/api/geocode/json?address=’ + encodeURIComponent(address) + ‘&sensor=false’ $.getJSON(url, function (data){ if (data.status == “OK”) { result = data.results[0].geometry.location; } }); return result; } ================================================== ================================ 鉴于回复,我现在已将代码更新为以下内容。 我仍然没有得到任何结果,在Firebug中设置断点结果= data.results [0] .geometry.location; […]