我尝试测试Bing Map API的准确性。我试图找出Chicago O'Hare International Airport
和Chicago Midway Airport
之间的距离和行车时间。 Bing Map 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
以上结果绝对不准确。 I compared manually the numbers with Bing Map
Click this link to see the difference。
当我尝试使用不同的地址时,驱动时间 在大多数情况下 可以正常计算。 。 。然而, 距离几乎总是 ,而不是我在地图中手动输入地址的距离。 。 。
是Bing Map API的问题吗?也许我应该以不同的方式使用getDistance
方法?
虽然距离接近Bing Map手动显示的距离,但不完全相同。他们怎么不一样?
谢谢!
答案 0 :(得分:7)
如果您手动使用实际坐标,考虑到几秒钟,驾驶时间似乎相同,请参阅test link。我得到35分钟,你的地板结果是34分钟。
现在,关于距离。在测试链接中,你可以看到它是26.7英里,而你的代码给出了42.898的结果(你自己添加了'里程'单位!)。现在,如果你convert your 26.7 miles to kilometers,你得到42.9695。因此,我会声称.getDistance()的结果实际上是千米而不是英里。
通过查看Route api似乎证实了这一点:
distanceUnit
杜
可选。在响应中用于距离的单位。
以下值之一:
- Mile或mi
- 公里或公里[默认]
所以你获得的数字非常准确。