Google地图方向API正在更改目标地址

发布于 2025-01-26 06:56:09 字数 1941 浏览 2 评论 0原文

我正在尝试使用Google Maps Directions API来计算路线的正确里程,并且它不断更改我的目的地地址从: 2369通过Mariposa E,Laguna Woods,CA 92637 to: B2369,2369通过Mariposa E,Laguna Woods,CA 92637

。 5.2mi。

感谢您的帮助!

            var origin = new GoogleApi.Entities.Common.Address("27020 Alicia Pkwy, Laguna Niguel, CA 92677, USA");
            var destination = new GoogleApi.Entities.Common.Address("2369 Via Mariposa E, Laguna Woods, CA 92637, USA");
            // For some reason, Destination changes to B2369, 2369 Via Mariposa E, Laguna Woods, CA 92637, USA
            // Expected Results: https://www.google.com/maps/dir/27020+Alicia+Pkwy,+Laguna+Niguel,+CA+92677/2369+Via+Mariposa+E,+Laguna+Woods,+CA+92637/@33.5899389,-117.746248,14z/data=!3m1!4b1!4m14!4m13!1m5!1m1!1s0x80dcef47fef5b78d:0xe6f974e512e89fdb!2m2!1d-117.7141775!2d33.5702304!1m5!1m1!1s0x80dce76420f8e66f:0x82dbfd8a0bfbe07f!2m2!1d-117.7497698!2d33.6096498!3e0
            // Returned Results: https://www.google.com/maps/dir/27020+Alicia+Pkwy,+Laguna+Niguel,+CA+92677/B2369,+2369+Via+Mariposa+E,+Laguna+Woods,+CA+92637/@33.5951275,-117.7294664,14z/data=!3m1!4b1!4m14!4m13!1m5!1m1!1s0x80dcef47fef5b78d:0xe6f974e512e89fdb!2m2!1d-117.7141775!2d33.5702304!1m5!1m1!1s0x80dce88a6a634ebf:0x8e9c99fbe8beeef9!2m2!1d-117.7181169!2d33.6198264!3e0

            var request = new DirectionsRequest()
            {
                Key = API,
                Origin = new LocationEx(origin),
                Destination = new LocationEx(destination),
                Avoid = GoogleApi.Entities.Maps.Common.Enums.AvoidWay.Tolls,
                TravelMode = GoogleApi.Entities.Maps.Common.Enums.TravelMode.Driving
            };
          

            var result = GoogleApi.GoogleMaps.Directions.Query(request);
            var meters = result.Routes.First().Legs.Sum(s => s.Distance.Value);
            routeData.Miles = getMiles(meters);

I'm trying to calculate the correct mileage of a route using Google Maps Directions API and it keeps changing my destination address FROM: 2369 Via Mariposa E, Laguna Woods, CA 92637 TO: B2369, 2369 Via Mariposa E, Laguna Woods, CA 92637.

Both are legitimate addresses if I go to the map (links provided in code below) but I can't seem to get Google to stop changing it resulting in 4.3mi instead of 5.2mi.

Thank you for your help!

            var origin = new GoogleApi.Entities.Common.Address("27020 Alicia Pkwy, Laguna Niguel, CA 92677, USA");
            var destination = new GoogleApi.Entities.Common.Address("2369 Via Mariposa E, Laguna Woods, CA 92637, USA");
            // For some reason, Destination changes to B2369, 2369 Via Mariposa E, Laguna Woods, CA 92637, USA
            // Expected Results: https://www.google.com/maps/dir/27020+Alicia+Pkwy,+Laguna+Niguel,+CA+92677/2369+Via+Mariposa+E,+Laguna+Woods,+CA+92637/@33.5899389,-117.746248,14z/data=!3m1!4b1!4m14!4m13!1m5!1m1!1s0x80dcef47fef5b78d:0xe6f974e512e89fdb!2m2!1d-117.7141775!2d33.5702304!1m5!1m1!1s0x80dce76420f8e66f:0x82dbfd8a0bfbe07f!2m2!1d-117.7497698!2d33.6096498!3e0
            // Returned Results: https://www.google.com/maps/dir/27020+Alicia+Pkwy,+Laguna+Niguel,+CA+92677/B2369,+2369+Via+Mariposa+E,+Laguna+Woods,+CA+92637/@33.5951275,-117.7294664,14z/data=!3m1!4b1!4m14!4m13!1m5!1m1!1s0x80dcef47fef5b78d:0xe6f974e512e89fdb!2m2!1d-117.7141775!2d33.5702304!1m5!1m1!1s0x80dce88a6a634ebf:0x8e9c99fbe8beeef9!2m2!1d-117.7181169!2d33.6198264!3e0

            var request = new DirectionsRequest()
            {
                Key = API,
                Origin = new LocationEx(origin),
                Destination = new LocationEx(destination),
                Avoid = GoogleApi.Entities.Maps.Common.Enums.AvoidWay.Tolls,
                TravelMode = GoogleApi.Entities.Maps.Common.Enums.TravelMode.Driving
            };
          

            var result = GoogleApi.GoogleMaps.Directions.Query(request);
            var meters = result.Routes.First().Legs.Sum(s => s.Distance.Value);
            routeData.Miles = getMiles(meters);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文