jjzjj

java - Bing Map API 与 Bing Map 手动 RouteRequest。 API不准确?

coder 2024-03-12 原文

我尝试测试 Bing Map API 的准确性。我试图找出 Chicago O'Hare International AirportChicago Midway Airport 之间的距离和行车时间。 Bing map API 似乎完全不准确。我用 bing map 手动检查了两次和三次。这是完整的代码

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 ");

    }


}

This is the link to the JARs


我得到的结果是

Bing Distance : 42.898 miles 
Driving Time : 34 minutes 

以上结果绝对不准确I compared manually the numbers with Bing Map Click this link to see the difference .

当我尝试使用不同的地址时,行车时间在大多数情况下都可以很好地计算。 . .然而,距离几乎总是比我在 Bing map 中手动输入地址时得到的距离高。 . .

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


虽然距离与 Bing map 手动显示的距离接近,但并不完全相同。他们怎么不一样?

谢谢!

最佳答案

如果您手动使用实际坐标,则行驶时间似乎与四舍五入的秒数相同,请参阅 test link .我得到 35 分钟,而你的最低结果是 34 分钟。

现在,关于距离。在测试链接中,您可以看到它是 26.7 英里,而您的代码给出的结果是 42.898(您自己在那里添加了“英里”单位!)。现在,如果你convert your 26.7 miles to kilometers ,你得到 42.9695。因此,我会声称 .getDistance() 的结果实际上是公里,而不是英里。

通过查看 Route api似乎证实了这一点:

distanceUnit

du

Optional. The units to use for distance in the response.

One of the following values:

  • Mile or mi
  • Kilometer or km [default]

所以你得到的数字在我看来是非常准确的。

关于java - Bing Map API 与 Bing Map 手动 RouteRequest。 API不准确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21359465/

有关java - Bing Map API 与 Bing Map 手动 RouteRequest。 API不准确?的更多相关文章

  1. java - 等价于 Java 中的 Ruby Hash - 2

    我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/

  2. ruby-on-rails - ActionController::RoutingError: 未初始化常量 Api::V1::ApiController - 2

    我有用于控制用户任务的Rails5API项目,我有以下错误,但并非总是针对相同的Controller和路由。ActionController::RoutingError:uninitializedconstantApi::V1::ApiController我向您描述了一些我的项目,以更详细地解释错误。应用结构路线scopemodule:'api'donamespace:v1do#=>Loginroutesscopemodule:'login'domatch'login',to:'sessions#login',as:'login',via::postend#=>Teamroutessc

  3. java - 从 JRuby 调用 Java 类的问题 - 2

    我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www

  4. java - 我的模型类或其他类中应该有逻辑吗 - 2

    我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我

  5. java - 什么相当于 ruby​​ 的 rack 或 python 的 Java wsgi? - 2

    什么是ruby​​的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht

  6. 【鸿蒙应用开发系列】- 获取系统设备信息以及版本API兼容调用方式 - 2

    在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList​()Obt

  7. Observability:从零开始创建 Java 微服务并监控它 (二) - 2

    这篇文章是继上一篇文章“Observability:从零开始创建Java微服务并监控它(一)”的续篇。在上一篇文章中,我们讲述了如何创建一个Javaweb应用,并使用Filebeat来收集应用所生成的日志。在今天的文章中,我来详述如何收集应用的指标,使用APM来监控应用并监督web服务的在线情况。源码可以在地址 https://github.com/liu-xiao-guo/java_observability 进行下载。摄入指标指标被视为可以随时更改的时间点值。当前请求的数量可以改变任何毫秒。你可能有1000个请求的峰值,然后一切都回到一个请求。这也意味着这些指标可能不准确,你还想提取最小/

  8. 【Java 面试合集】HashMap中为什么引入红黑树,而不是AVL树呢 - 2

    HashMap中为什么引入红黑树,而不是AVL树呢1.概述开始学习这个知识点之前我们需要知道,在JDK1.8以及之前,针对HashMap有什么不同。JDK1.7的时候,HashMap的底层实现是数组+链表JDK1.8的时候,HashMap的底层实现是数组+链表+红黑树我们要思考一个问题,为什么要从链表转为红黑树呢。首先先让我们了解下链表有什么不好???2.链表上述的截图其实就是链表的结构,我们来看下链表的增删改查的时间复杂度增:因为链表不是线性结构,所以每次添加的时候,只需要移动一个节点,所以可以理解为复杂度是N(1)删:算法时间复杂度跟增保持一致查:既然是非线性结构,所以查询某一个节点的时候

  9. ruby-on-rails - Mandrill API 模板 - 2

    我正在使用Mandrill的RubyAPIGem并使用以下简单的测试模板:testastic按照Heroku指南中的示例,我有以下Ruby代码:require'mandrill'm=Mandrill::API.newrendered=m.templates.render'test-template',[{:header=>'someheadertext',:main_section=>'Themaincontentblock',:footer=>'asdf'}]mail(:to=>"JaysonLane",:subject=>"TestEmail")do|format|format.h

  10. ruby-on-rails - 在 Ruby (on Rails) 中使用 imgur API 获取图像 - 2

    我正在尝试使用Ruby2.0.0和Rails4.0.0提供的API从imgur中提取图像。我已尝试按照Ruby2.0.0文档中列出的各种方式构建http请求,但均无济于事。代码如下:require'net/http'require'net/https'defimgurheaders={"Authorization"=>"Client-ID"+my_client_id}path="/3/gallery/image/#{img_id}.json"uri=URI("https://api.imgur.com"+path)request,data=Net::HTTP::Get.new(path

随机推荐