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

      • <bdo id='0dmrv'></bdo><ul id='0dmrv'></ul>
    1. <small id='0dmrv'></small><noframes id='0dmrv'>

      <tfoot id='0dmrv'></tfoot>
      1. 从函数中获取经度和纬度值

        时间:2023-09-05

          <small id='07wVj'></small><noframes id='07wVj'>

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

            <legend id='07wVj'><style id='07wVj'><dir id='07wVj'><q id='07wVj'></q></dir></style></legend>

              1. <tfoot id='07wVj'></tfoot>
                  <tbody id='07wVj'></tbody>

                  <bdo id='07wVj'></bdo><ul id='07wVj'></ul>
                  本文介绍了从函数中获取经度和纬度值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  请问我如何在它们的函数之外获取lat"和lon"的值,以便在页面上的其他位置使用.

                  Please how do i get the value of "lat" and "lon" outside their function to use else where on the page.

                     navigator.geolocation.getCurrentPosition(handle_geolocation_query,handle_errors);  
                  
                      function handle_errors(error)  
                      {  
                          switch(error.code)  
                          {  
                              case error.PERMISSION_DENIED: alert("user did not share geolocation data");  
                              break;  
                              case error.POSITION_UNAVAILABLE: alert("could not detect current position");  
                              break;  
                              case error.TIMEOUT: alert("retrieving position timed out");  
                              break;  
                              default: alert("unknown error");  
                              break;  
                          }  
                      }  
                     function handle_geolocation_query(position){  
                          var lat = (position.coords.latitude);
                         var lon = (position.coords.longitude); 
                  
                      }
                  

                  我要做的是获取设备的经度和纬度并将其作为参数传递给查询和数据库,也将相同的值用于其他事物.我不知道该怎么做.任何帮助将不胜感激.

                  What i am trying to do is to get the longitude and latitude of a device and pass it is as a parameter to query and database, also use that same value for other things. I cant figure out how to go about it. Any help will be much appreciated.

                  推荐答案

                  我想到的第一件事(在这么晚的时间:D)是这样的:

                  The first thing came my mind (at this late hour :D) is something like this:

                  • 在处理程序之外声明一个变量,比如说:

                  • declare a variable outside your handlers, let's say:

                  var coords = {};

                  var coords = {};

                  然后在你的 'handle_geolocation_query' 处理程序中,触发一个事件,让你知道你的位置已经准备好,假设你正在使用 jQuery:

                  then in your 'handle_geolocation_query' handler, trigger an event that gives you an ideea that your position is ready, assuming you're using jQuery:

                  $(coords).trigger('positionReady', position);

                  $(coords).trigger('positionReady', position);

                  之后,在您需要这些坐标的任何地方,监听您的自定义positionReady"事件,然后完成您的工作:

                  after that, everywhere you need those coordinates, listen for your custom 'positionReady' event, and do your job:

                  $(coords).on('positionReady', function(e, position) {控制台.log(位置);});

                  $(coords).on('positionReady', function(e, position) { console.log(position); });

                  这将帮助您避免意大利面条式代码",但同时,您需要异步思考",并且可能以您需要的(正确)方式使用回调.

                  This will help you to avoid 'spaghetti code', but in the same time, you need to 'think' asynchronously, and maybe using callbacks the (right) way you need.

                  这篇关于从函数中获取经度和纬度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在谷歌地图中仅显示特定国家(地区) 下一篇:用户在 javascript 中阻止访问后请求位置坐标

                  相关文章

                  最新文章

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

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

                    <tfoot id='Mt5Sw'></tfoot>

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