必应地图API vs 必应地图手动RouteRequest。API准确吗?

8

我试图测试Bing地图API的准确性。我尝试找出芝加哥奥黑尔国际机场和芝加哥中途机场之间的距离和驾车时间。看起来Bing地图API完全不准确。我手动使用Bing地图进行了双重和三重检查。下面是完整的代码:

import net.virtualearth.dev.webservices.v1.common.Credentials;
import net.virtualearth.dev.webservices.v1.common.Location;
import net.virtualearth.dev.webservices.v1.route.BasicHttpBinding_IRouteServiceStub;
import net.virtualearth.dev.webservices.v1.route.RouteRequest;
import net.virtualearth.dev.webservices.v1.route.RouteResponse;
import net.virtualearth.dev.webservices.v1.route.RouteResult;
import net.virtualearth.dev.webservices.v1.route.RouteServiceLocator;
import net.virtualearth.dev.webservices.v1.route.RouteSummary;
import net.virtualearth.dev.webservices.v1.route.Waypoint;

public class Test {


    public static void main(String[] args) throws Exception {

         double [] address1Coordinate = {  41.97980880737305   ,   -87.88204193115234 } ; // Chicago O'Hare International Airport, IL  [I checked the coordinate . It is accurate ]
         double [] address2Coordinate = {  41.7872200012207    ,   -87.74160766601562 } ; // Chicago Midway Airport, IL  [I checked the coordinate . It is accurate ]

        BasicHttpBinding_IRouteServiceStub routeService = (BasicHttpBinding_IRouteServiceStub) (new RouteServiceLocator()).getBasicHttpBinding_IRouteService();

        RouteRequest request = new RouteRequest();
        Credentials creds = new Credentials();
        // I got my Bing map key from here http://msdn.microsoft.com/en-us/library/ff428642.aspx and entered it below : 
        creds.setApplicationId("This is my Bing App Key . . . ");
        request.setCredentials(creds);
        Waypoint[] waypoints = new Waypoint[2];
        waypoints[0] = new Waypoint();
        Location start = new Location();
        start.setLatitude(address1Coordinate[0]); 
        start.setLongitude(address1Coordinate[1]); 
        waypoints[0].setLocation(start);
        waypoints[1] = new Waypoint();
        Location end = new Location();
        end.setLatitude(address2Coordinate[0]); 
        end.setLongitude(address2Coordinate[1]) ; 
        waypoints[1].setLocation(end);
        request.setWaypoints(waypoints);

        RouteResponse response = routeService.calculateRoute(request);
        RouteResult result = response.getResult();

        RouteSummary routeSummary = result.getSummary();

        System.out.println( "Bing Distance : " + routeSummary.getDistance() + " miles ");   
        System.out.println( "Driving Time : " + routeSummary.getTimeInSeconds()/60 + " minutes ");

    }


}

这是JAR文件的链接


我得到的结果是

Bing Distance : 42.898 miles 
Driving Time : 34 minutes 

以上结果绝对不准确我手动比较了数字和 Bing Map,单击此链接可查看差异。

当我尝试使用不同的地址时,大多数情况下驾车时间会被正确计算...然而距离几乎总是比手动输入地址到 Bing Map 中得到的距离更长...

这是 Bing Map API 的问题吗?也许我应该以不同的方式使用 getDistance 方法?


虽然距离接近 Bing Map 手动显示的距离,但不完全相同。为什么它们不同?

谢谢!


2
我检查过了……虽然我没有足够的声望来说这个,但看起来这是API中的一个错误。 - Бывший Мусор
英里?必应 API 什么时候开始使用英制单位了? - ooxi
1个回答

7
如果您手动使用实际坐标,则由于秒数舍入而导致驾驶时间相同,详见测试链接。我得到的是35分钟,而你得出的结果是34分钟,向下取整了。
现在,关于距离。在测试链接中,您可以看到它是26.7英里,而您的代码给出了42.898的结果(您自己添加了“英里”单位!)。现在,如果您将您的26.7英里转换为公里,您将得到42.9695。因此,我认为.getDistance()的结果实际上是公里,而不是英里。
通过查看路由api,似乎确认了这一点:

distanceUnit

du

可选。响应中用于距离的单位。

以下值之一:

  • 英里或mi
  • 千米或km [默认]
所以,我认为您得到的数字非常准确。

1
我猜“km”注释是正确的。但是,恕我直言,尽管数字很接近,但手动使用相同的Bing地图得到的数字与之不同。问题是:Bing是从哪里获取这些数字的?为什么它们不一样? - Buras
1
@Buras 嗯,手动数字四舍五入比Java API更多。向终端用户显示4个小数位是没有意义的。即使使用手动方式,差异也比显示的数字数量小。如果精度不同,它们怎么可能完全相等呢?如果距离为42.898公里,您希望手动数字表示多少英里呢?应该是26.7。 - eis

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接