1. <legend id='pj3WL'><style id='pj3WL'><dir id='pj3WL'><q id='pj3WL'></q></dir></style></legend>

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

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

      • <bdo id='pj3WL'></bdo><ul id='pj3WL'></ul>
    2. <tfoot id='pj3WL'></tfoot>

    3. 如何使 Geolocation API 函数在 localhost file://上工作

      时间:2023-09-05
            <tbody id='EEyCk'></tbody>

          <tfoot id='EEyCk'></tfoot>
        • <small id='EEyCk'></small><noframes id='EEyCk'>

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

                本文介绍了如何使 Geolocation API 函数在 localhost file://上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我有这个基本代码来使用 Geolocation API 检索纬度和经度:

                I have this basic code to retrieve latitude and longitude with Geolocation API :

                showmap.html

                <button  onclick="getLocation()">Find me </button>
                
                <script type="text/javascript" src="js/geolocation.js"></script>
                

                js/geolocation.js

                function getLocation() {
                
                  if (navigator.geolocation) {
                    navigator.geolocation.getCurrentPosition(showPosition);
                  } else { 
                    alert("Geolocation is not supported by your browser. Please update your browser. Visit Help Center.");
                  }
                }
                
                function showPosition(position) {
                  var latitude = position.coords.latitude;
                  var longitude =  position.coords.longitude;
                
                  console.log("Latitude : " + latitude + "<br> Longitude :" + longitude);
                }
                

                当我单击按钮时,我在控制台中收到此错误

                When I click on the button I receive this error in the console

                SyntaxError: An invalid or illegal string was specified showmap.html:72
                    _sendMessage file:///home/user/Desktop/Projects/showmap.html:72
                    call file:///home/user/Desktop/Projects/showmap.html:64
                    getCurrentPosition file:///home/user/Desktop/Projects/showmap.html:16
                    getLocation file:///home/user/Desktop/Projects/js/geolocation.js:4
                    onclick file:///home/user/Desktop/Projects/showmap.html:1
                    fireMouseEvent resource://devtools/server/actors/emulation/touch-simulator.js:290
                    dispatchMouseEvents resource://devtools/server/actors/emulation/touch-simulator.js:264
                

                我正在尝试找出解决此问题的方法.这不工作,因为我在 file:// ?

                I'm trying to figure out how to solve this issue. Is this not working because I'm in file:// ?

                推荐答案

                要让 file: 使用 Geolocation Api,运行 ngrok 并使用 https 网址来托管您的 HTML 应用程序.无需 PHP 或 Python 等后端语言,您可以使用您的凭据生成本地隧道.

                To get file: to work with Geolocation Api, run ngrok and use the https url to host your HTML app. No need for PHP or backend language like Python, you can generate a local tunnel using your credentials.

                这假设您已安装 ngrok 并且您正在运行 Ubuntu.

                This assumes you have ngrok installed and that you are running Ubuntu.

                打开终端并运行:

                ngrok http -auth="user:password" file:///path/to/your/HTML/project
                

                参考:使用 ngrok 的内置文件服务器服务本地目录https://ngrok.com/docs

                Reference : Serving local directories with ngrok's built-in fileserver https://ngrok.com/docs

                这篇关于如何使 Geolocation API 函数在 localhost file://上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用 javascript 获取我当前的地址 下一篇:@JdbcInsert 插入多个条目

                相关文章

                最新文章

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

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

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