0

我使用 Google Maps API v3 显示从用户定义的起点到我的财产的路线。

除了端点的准确性之外,这在技术上工作正常。我已将我的财产的经度/纬度定义为准确的点,但方向仍会将您带到大约 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();

            });

        }
4

2 回答 2

1

假设x,yingetDirections(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();

        });

    }
于 2013-06-22T07:56:58.127 回答
0

您可以传递一个“半径”变量。不知道如何在 JS 中做,但使用 web-api 看看这个:

http://cbk0.google.com/cbk?output=xml&ll=43.19199,-5.4288&radius=500

它什么也不返回

将半径更改为 5000,您会得到一个结果。如果这不起作用,请尝试更高的缩放级别?

于 2013-08-23T23:07:41.267 回答