我告诉我的计算机允许对localhost进行地理定位,但我仍然得到两个坐标的空值.我该如何解决这个问题呢?

I told my computer to allow geolocation to localhost, and I'm still getting null for both coordinnates. How can I address this?

本文关键字:坐标 两个 空值 问题 解决 何解决 计算机 我的 localhost 定位      更新时间:2023-09-26

我有:

        ANCIENT_CLOCK.latitude = null;
        ANCIENT_CLOCK.longitude = null;
        ANCIENT_CLOCK.register_position = function(position)
            {
            ANCIENT_CLOCK.latitude = position.coords.latitude;
            ANCIENT_CLOCK.longitude = position.coords.longitude;
            }
        if (Modernizr.geolocation)
            {
            navigator.geolocation.getCurrentPosition(ANCIENT_CLOCK.register_position);
            }

我有一个Chrome实例,我已经同意让localhost使用地理空间位置,并且除了我在console.log()中调用的调试输出外,控制台上没有任何东西。然而,ANCIENT_CLOCK。纬度和古代时钟。经度都为空

我能做些什么来获得(非空)坐标的用户谁选择了?

这段代码看起来工作得很好,但是您没有向我们展示发现值为null的代码。

赔率有利于您在调用register_position回调之前检查值(例如,在调用navigator.geolocation之后立即使用console.log(ANCIENT_CLOCK))。

将依赖于地理位置数据的逻辑移到回调中