使用Long/Lat与谷歌地图API的方向准确性

Accuracy of directions using Long/Lat with Google Maps API

本文关键字:API 方向 准确性 谷歌地图 Long Lat 使用      更新时间:2023-09-26

我使用Google Maps API v3来显示从用户定义的起点到我的属性的方向。

除了结束点的准确性之外,这在技术上是可以工作的。我已经把我的房子的Long/Lat定义到确切的点,但方向仍然把你带到大约100米外的一条街上。

是否有一种方法可以迫使方向带你到一个精确的点?

这是我的代码,如果它有帮助…

function getDirections(x, y) {
            $("#directionsPanel").html("");
            var directionsService = new google.maps.DirectionsService();
            var directionsDisplay = new google.maps.DirectionsRenderer();
            var myOptions = {
                zoom: 10,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                scrollwheel: false
            }
            var map = new google.maps.Map(document.getElementById("map"), myOptions);
            directionsDisplay.setPanel(document.getElementById('directionsPanel'));
            directionsDisplay.setMap(map);
            var request = {
                origin: x,
                destination: $('.lat').text() + ',' + $('.lng').text() ,
                travelMode: google.maps.DirectionsTravelMode.DRIVING,
                unitSystem: google.maps.UnitSystem.IMPERIAL,
                provideRouteAlternatives: true,
                region: "GB"
            };
            directionsService.route(request, function (response, status) {
                    directionsDisplay.setDirections(response);
                    $(".noValidRoute").hide();
            });
        }

假设getDirections(x, y)中的x,y是您的属性的坐标,您只使用x

;
function getDirections(x, y) {
        var origin = new google.maps.LatLng(x,y)
        $("#directionsPanel").html("");
        var directionsService = new google.maps.DirectionsService();
        var directionsDisplay = new google.maps.DirectionsRenderer();
        var myOptions = {
            zoom: 10,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            scrollwheel: false
        }
        var map = new google.maps.Map(document.getElementById("map"), myOptions);
        directionsDisplay.setPanel(document.getElementById('directionsPanel'));
        directionsDisplay.setMap(map);
        var request = {
            origin: origin,
            destination: $('.lat').text() + ',' + $('.lng').text() ,
            travelMode: google.maps.DirectionsTravelMode.DRIVING,
            unitSystem: google.maps.UnitSystem.IMPERIAL,
            provideRouteAlternatives: true,
            region: "GB"
        };
        directionsService.route(request, function (response, status) {
                directionsDisplay.setDirections(response);
                $(".noValidRoute").hide();
        });
    }

有一个可以传递的"radius"变量。不知道如何在JS中做,但与web-api看看这个:

http://cbk0.google.com/cbk?output=xml&你= 43.19199、-5.4288,半径= 500

它什么也不返回

将半径更改为5000,您将得到一个结果。如果不行,试试更高的变焦级别?