<i id='c9Jx7'><tr id='c9Jx7'><dt id='c9Jx7'><q id='c9Jx7'><span id='c9Jx7'><b id='c9Jx7'><form id='c9Jx7'><ins id='c9Jx7'></ins><ul id='c9Jx7'></ul><sub id='c9Jx7'></sub></form><legend id='c9Jx7'></legend><bdo id='c9Jx7'><pre id='c9Jx7'><center id='c9Jx7'></center></pre></bdo></b><th id='c9Jx7'></th></span></q></dt></tr></i><div id='c9Jx7'><tfoot id='c9Jx7'></tfoot><dl id='c9Jx7'><fieldset id='c9Jx7'></fieldset></dl></div>
      <bdo id='c9Jx7'></bdo><ul id='c9Jx7'></ul>
  • <legend id='c9Jx7'><style id='c9Jx7'><dir id='c9Jx7'><q id='c9Jx7'></q></dir></style></legend>

    <small id='c9Jx7'></small><noframes id='c9Jx7'>

        <tfoot id='c9Jx7'></tfoot>
      1. 谷歌的地理编码器返回错误的国家,忽略地区提

        时间:2023-09-06
        • <small id='GjUCH'></small><noframes id='GjUCH'>

            <tbody id='GjUCH'></tbody>
            <tfoot id='GjUCH'></tfoot>

            <legend id='GjUCH'><style id='GjUCH'><dir id='GjUCH'><q id='GjUCH'></q></dir></style></legend>

              <i id='GjUCH'><tr id='GjUCH'><dt id='GjUCH'><q id='GjUCH'><span id='GjUCH'><b id='GjUCH'><form id='GjUCH'><ins id='GjUCH'></ins><ul id='GjUCH'></ul><sub id='GjUCH'></sub></form><legend id='GjUCH'></legend><bdo id='GjUCH'><pre id='GjUCH'><center id='GjUCH'></center></pre></bdo></b><th id='GjUCH'></th></span></q></dt></tr></i><div id='GjUCH'><tfoot id='GjUCH'></tfoot><dl id='GjUCH'><fieldset id='GjUCH'></fieldset></dl></div>
                • <bdo id='GjUCH'></bdo><ul id='GjUCH'></ul>
                  本文介绍了谷歌的地理编码器返回错误的国家,忽略地区提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 Google 的地理编码器来查找给定地址的 lat lng 坐标.

                  I'm using Google's Geocoder to find lat lng coordinates for a given address.

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

                  address 变量取自输入字段.

                  我想搜索仅在英国的位置.我认为指定 'region': 'uk' 应该就足够了,但事实并非如此.当我输入波士顿"时,它会在美国找到波士顿,而我想要在英国找到波士顿.

                  I want to search locations only in UK. I thought that specifying 'region': 'uk' should be enough but it's not. When I type in "Boston" it's finding Boston in US and I wanted the one in UK.

                  如何限制地理编码器仅返回来自一个国家或可能来自某个 lat lng 范围的位置?

                  How to restrict Geocoder to return locations only from one country or maybe from a certain lat lng range?

                  谢谢

                  推荐答案

                  更新: 这个答案可能不再是最好的方法了.有关详细信息,请参阅答案下方的评论.

                  UPDATE: This answer may not be the best approach anymore. See the comments below the answer for more details.

                  除了Pekka 已经建议,您可能还想要将 ', UK' 连接到您的 address,如下例所示:

                  In addition to what Pekka already suggested, you may want to concatenate ', UK' to your address, as in the following example:

                  <!DOCTYPE html>
                  <html> 
                  <head> 
                     <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
                     <title>Google Maps Geocoding only in UK Demo</title> 
                     <script src="http://maps.google.com/maps/api/js?sensor=false" 
                             type="text/javascript"></script> 
                  </head> 
                  <body> 
                     <div id="map" style="width: 400px; height: 300px"></div> 
                  
                     <script type="text/javascript"> 
                  
                     var mapOptions = { 
                        mapTypeId: google.maps.MapTypeId.TERRAIN,
                        center: new google.maps.LatLng(54.00, -3.00),
                        zoom: 5
                     };
                  
                     var map = new google.maps.Map(document.getElementById("map"), mapOptions);
                     var geocoder = new google.maps.Geocoder();
                  
                     var address = 'Boston';
                  
                     geocoder.geocode({
                        'address': address + ', UK'
                     }, 
                     function(results, status) {
                        if(status == google.maps.GeocoderStatus.OK) {
                           new google.maps.Marker({
                              position:results[0].geometry.location,
                              map: map
                           });
                        }
                     });
                  
                     </script> 
                  </body> 
                  </html>
                  

                  截图:

                  我发现这是非常可靠的.另一方面,下面的例子表明 region 参数和 bounds 参数在这种情况下都不起作用:

                  I find that this is very reliable. On the other hand, the following example shows that neither the region parameter, nor the bounds parameter, are having any effect in this case:

                  <!DOCTYPE html>
                  <html> 
                  <head> 
                     <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
                     <title>Google Maps Geocoding only in UK Demo with Bounds</title> 
                     <script src="http://maps.google.com/maps/api/js?sensor=false" 
                             type="text/javascript"></script> 
                  </head> 
                  <body> 
                     <div id="map" style="width: 500px; height: 300px"></div> 
                  
                     <script type="text/javascript"> 
                  
                     var mapOptions = { 
                        mapTypeId: google.maps.MapTypeId.TERRAIN,
                        center: new google.maps.LatLng(50.00, -33.00),
                        zoom: 3
                     };
                  
                     var map = new google.maps.Map(document.getElementById("map"), mapOptions);   
                     var geocoder = new google.maps.Geocoder();
                  
                     // Define north-east and south-west points of UK
                     var ne = new google.maps.LatLng(60.00, 3.00);
                     var sw = new google.maps.LatLng(49.00, -13.00);
                  
                     // Define bounding box for drawing
                     var boundingBoxPoints = [
                        ne, new google.maps.LatLng(ne.lat(), sw.lng()),
                        sw, new google.maps.LatLng(sw.lat(), ne.lng()), ne
                     ];
                  
                     // Draw bounding box on map    
                     new google.maps.Polyline({
                        path: boundingBoxPoints,
                        strokeColor: '#FF0000',
                        strokeOpacity: 1.0,
                        strokeWeight: 2,
                        map: map
                     });
                  
                     // Geocode and place marker on map
                     geocoder.geocode({
                        'address': 'Boston',
                        'region':  'uk',
                        'bounds':  new google.maps.LatLngBounds(sw, ne)
                     }, 
                     function(results, status) {
                        if(status == google.maps.GeocoderStatus.OK) {
                           new google.maps.Marker({
                              position:results[0].geometry.location,
                              map: map
                           });
                        }
                     });
                  
                     </script> 
                  </body> 
                  </html>
                  

                  这篇关于谷歌的地理编码器返回错误的国家,忽略地区提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 angularjs 中使用 HTML5 地理位置 下一篇:如何在javascript内部进行base64编码

                  相关文章

                  最新文章

                • <legend id='5Q0xY'><style id='5Q0xY'><dir id='5Q0xY'><q id='5Q0xY'></q></dir></style></legend>
                      <bdo id='5Q0xY'></bdo><ul id='5Q0xY'></ul>

                    <small id='5Q0xY'></small><noframes id='5Q0xY'>

                    <i id='5Q0xY'><tr id='5Q0xY'><dt id='5Q0xY'><q id='5Q0xY'><span id='5Q0xY'><b id='5Q0xY'><form id='5Q0xY'><ins id='5Q0xY'></ins><ul id='5Q0xY'></ul><sub id='5Q0xY'></sub></form><legend id='5Q0xY'></legend><bdo id='5Q0xY'><pre id='5Q0xY'><center id='5Q0xY'></center></pre></bdo></b><th id='5Q0xY'></th></span></q></dt></tr></i><div id='5Q0xY'><tfoot id='5Q0xY'></tfoot><dl id='5Q0xY'><fieldset id='5Q0xY'></fieldset></dl></div>
                    <tfoot id='5Q0xY'></tfoot>