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

    1. <small id='9wx2d'></small><noframes id='9wx2d'>

        <tfoot id='9wx2d'></tfoot>
          <bdo id='9wx2d'></bdo><ul id='9wx2d'></ul>
      1. 使用 javascript 获取我当前的地址

        时间:2023-09-05

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

              1. <small id='REvKj'></small><noframes id='REvKj'>

                  本文介绍了使用 javascript 获取我当前的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我对使用 Javascript 获取当前地址很感兴趣,只是通过组装其他一些 SO 线程来解决这个问题(1,2) 所以想发布这个问题和答案.

                  I was interested in getting my current address using Javascript and just figured this out by assembling some other SO threads (1,2) so wanted to post this question and answer.

                  请看下面的答案.

                  推荐答案

                  这是 HTML:

                  <script src="http://maps.google.com/maps/api/js?sensor=false"></script>
                  <p id='latitudeAndLongitude'></p>
                  <p id='address'></p> 
                  

                  这是 JS:

                  var latitudeAndLongitude=document.getElementById("latitudeAndLongitude"),
                  location={
                      latitude:'',
                      longitude:''
                  };
                  
                  if (navigator.geolocation){
                    navigator.geolocation.getCurrentPosition(showPosition);
                  }
                  else{
                    latitudeAndLongitude.innerHTML="Geolocation is not supported by this browser.";
                  }
                  
                  function showPosition(position){ 
                      location.latitude=position.coords.latitude;
                      location.longitude=position.coords.longitude;
                      latitudeAndLongitude.innerHTML="Latitude: " + position.coords.latitude + 
                      "<br>Longitude: " + position.coords.longitude; 
                      var geocoder = new google.maps.Geocoder();
                      var latLng = new google.maps.LatLng(location.latitude, location.longitude);
                  
                   if (geocoder) {
                      geocoder.geocode({ 'latLng': latLng}, function (results, status) {
                         if (status == google.maps.GeocoderStatus.OK) {
                           console.log(results[0].formatted_address); 
                           $('#address').html('Address:'+results[0].formatted_address);
                         }
                         else {
                          $('#address').html('Geocoding failed: '+status);
                          console.log("Geocoding failed: " + status);
                         }
                      }); //geocoder.geocode()
                    }      
                  } //showPosition
                  

                  这篇关于使用 javascript 获取我当前的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:“file:///C:/"上不允许 navigator.geolocation.getCur 下一篇:如何使 Geolocation API 函数在 localhost file://上工作

                  相关文章

                  最新文章

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

                • <tfoot id='g1v8p'></tfoot>

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

                    <bdo id='g1v8p'></bdo><ul id='g1v8p'></ul>

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