Java Bing地图API与Bing地图手动路由请求。API是否不准确?
我试着测试Bing地图API的准确性。我试图找出Java Bing地图API与Bing地图手动路由请求。API是否不准确?,java,bing-api,Java,Bing Api,我试着测试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.w
芝加哥奥黑尔国际机场
和芝加哥中途岛机场
之间的距离和驾驶时间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 ");
}
}
我得到的结果是
Bing Distance : 42.898 miles
Driving Time : 34 minutes
上述结果绝对不准确
当我尝试使用不同的地址时,在大多数情况下,驾驶时间都可以很好地计算出来。然而,距离几乎总是比我在Bing地图上手动输入地址的距离要高
这是Bing地图API的问题吗?也许我应该以另一种方式使用getDistance
方法
虽然距离接近Bing地图手动显示的距离,但并不完全相同。为什么它们不一样
谢谢大家! 如果手动使用实际坐标,则在给定的四舍五入秒数下,驾驶时间似乎相同,请参阅。我有35分钟,你的总成绩是34分钟 现在,关于距离。在测试链接中,您可以看到它是26.7英里,而您的代码给出的结果是42.898英里(您自己在那里添加了“英里”单位!)。现在,如果你,你得到42.9695。因此,我认为.getDistance()的结果实际上是公里,而不是英里 通过观察,似乎可以证实这一点: 距离单位 杜 可选。响应中用于距离的单位 下列值之一:
- 英里或英里
- 公里或公里[默认值]
所以你得到的数字在我看来非常准确。我检查过了。我并没有足够的声誉说这句话,但它似乎是一个和apiMiles的错误?bing什么时候开始在API中使用英制单位了?我想“km”的注释是正确的。然而,恕我直言,虽然数字很接近,但与您手动尝试相同的Bing地图的情况不同。问题是:必应从哪里获得这些数字?为什么它们不一样?@Buras-um,手动数字比java api给出的更精确。向最终用户显示4位数字是没有意义的。差值小于手动使用时显示的位数。如果精度不一样,它们怎么可能100%相等?如果距离为42.898公里,您希望手动数字以英里为单位是多少?26.7应该是这样。