Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript geolocation.getCurrentPosition问题_Javascript_Jquery_Geolocation - Fatal编程技术网

Javascript geolocation.getCurrentPosition问题

Javascript geolocation.getCurrentPosition问题,javascript,jquery,geolocation,Javascript,Jquery,Geolocation,我有一个关于地理位置的问题。getCurrentPosition() 我有以下代码: $(document).on('click', '#find_pickupStoresNearMe_button', function (e) { e.preventDefault(); var formAction = $(this).parents('form').attr('action'); $('#locationForSearch').val(''); navigat

我有一个关于地理位置的问题。getCurrentPosition()

我有以下代码:

$(document).on('click', '#find_pickupStoresNearMe_button', function (e) {
    e.preventDefault();
    var formAction = $(this).parents('form').attr('action');
    $('#locationForSearch').val('');
    navigator.geolocation.getCurrentPosition(function (position) {
        console.log(position);
        ACC.pickupinstore.locationSearchSubmit('', formAction, position.coords.latitude, position.coords.longitude);
    }, function (error) {
        console.log("An error occurred... The error code and message are: " + error.code + "/" + error.message);
    });
});
问题是函数直接跳入函数(错误),因为位置未定义。我在不同的文件夹中为不同的商店使用相同的代码,html结构相同,在搜索输入中检索我请求的城市效果良好

HTML代码:

<form id="command" name="pickupInStoreForm" class="searchPOSForm clearfix" action="/store/store-pickup/pointOfServices"
    method="POST">
    <table>
        <tbody>
            <tr>
                <td>
                    <div class="control-group left">
                        <div class="controls">
                            <input type="text" name="locationQuery" id="locationForSearch" class="left" placeholder="Adauga Oras">
                        </div>
                    </div>
                </td>
                <td>
                    <button type="button" class="" id="pickupstore_search_button">Gaseste magazin</button>
                </td>
                <td>
                    <button type="button" class="" id="find_pickupStoresNearMe_button">Localizeaza pozitia pe harta</button>
                </td>
            </tr>
        </tbody>
    </table>
    <div>

马加津酒店
波兹蒂亚佩哈塔地方酒店
我不熟悉javascript和jQuery,如果问题陈述不当或需要额外信息,请告诉我。如果您能帮助我查找问题的位置,我们将不胜感激。

请检查这些方法是否有效

$(function($) {
    $('#pickupstore_search_button').on('click', (e) => {
      e.preventDefault();
      navigator.geolocation.getCurrentPosition((pos) => {
        console.log(pos)
      }, (err) => {
         console.error(err)
      });
    });
});
否则,单击URL之前的锁定符号(https之前),转到“站点设置”并将位置设置为“询问默认值”或“允许”

也许吧


也许您已经永久性地“封锁”了某个特定站点的位置?(getCurrentPosition只适用于https站点,你知道很多,对吧?)你收到的错误代码/消息是什么。@ShivKumarBaghel只是弹出了一个函数(错误),它跳过了第一个调用的函数,控制台中没有语法错误。@JaromandaX不是这样,它在另一个具有相同代码的商店中工作,我没有语法错误,也没有锁符号。同样的问题,我在控制台中放置了断点,在它到达getCurrentPosition后,它跳出函数(它不在控制台记录任何内容,也不记录pos或err)你是否尝试单击锁符号?我在URL之前没有看到锁符号谢谢,它完成了任务,锁符号就是问题所在