【问题标题】:Mapbox showing location from my Internet service provider(ISP) IP addressMapbox 显示来自我的 Internet 服务提供商 (ISP) IP 地址的位置
【发布时间】:2020-12-14 01:59:06
【问题描述】:

Mapbox 显示来自我的 Internet 服务提供商 (ISP) IP 地址的位置,而不是来自通过 WIFI 连接到我的家庭网络的桌面的 IP 地址,但是,它确实跟踪连接到同一设备的移动设备的正确位置家庭网络。

我将如何解决这个问题?

索引.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src='https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.js'></script>
    <script src="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-directions/v4.1.0/mapbox-gl-directions.js"></script>
    <link href='https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.css' rel='stylesheet'/>
    <link rel="stylesheet" href="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-directions/v4.1.0/mapbox-gl-directions.css" type="text/css"/>
    <title>Mapbox Test</title>
</head>
<body>
    <div id='map' ></div> 
    <script src="js/basic_map.js" defer></script>
</body>
</html>

basic_map.js:

// mapbox access Key
mapboxgl.accessToken = ACCESS_TOKEN;

// Get My Current Location
navigator.geolocation.getCurrentPosition(successLocation, errorLocation, { enableHighAccuracy: true});

function successLocation(position)
{
    center = [position.coords.longitude, position.coords.latitude];
    zoom = 15;
    setupMap(center, zoom);
}

function errorLocation()
{
    // Fallback: Cape Town
    center = [18.4241, -33.9249];
    zoom = 10;
    setupMap(center, zoom);
}

function setupMap(center,zoom)
{
    const map = new mapboxgl.Map({
        container: 'map',
        style: 'mapbox://styles/mapbox/streets-v11',
        center: center,
        zoom: zoom
        });



    map.on('load', function() 
    {
        // Add Navigation Buttons
        const nav = new mapboxgl.NavigationControl();
        map.addControl(nav, 'top-right');

        //  Add Marker
        const  marker = new mapboxgl.Marker()
        .setLngLat(center)
        .addTo(map);
    });
}

【问题讨论】:

    标签: mapbox mapbox-gl-js mapbox-gl mapbox-marker


    【解决方案1】:

    这只是地理定位工作方式的固有特性。移动设备中装有 GPS,外加 3G/4G、wi-fi 等 - 有很多方法可以知道它在哪里。台式计算机没有这些信息:只有它的 IP 地址。因此,地理定位服务正在做出最佳猜测,并在您的 ISP 处结束。

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 2021-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-24
      • 2020-03-06
      • 2019-03-03
      • 1970-01-01
      相关资源
      最近更新 更多