Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bing Map API vs Bing Map manual RouteRequest . Is the API inaccurate?

Tags:

java

bing-api

I tried to test Bing Map API's accuracy . I tried to find out the distance and driving time between Chicago O'Hare International Airport and Chicago Midway Airport . It appears that Bing Map API is completely inaccurate . I double and triple checked it manually with bing maps . Here is the complete code

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


The result that I got was

Bing Distance : 42.898 miles 
Driving Time : 34 minutes 

The above results are absolutely inaccurate . I compared manually the numbers with Bing Map Click this link to see the difference.

When I tried using different addresses , the driving time would in most cases be calculated fine . . . however the distance is almost always higher than the one that I would get typing in the addresses manually into the Bing Map . . .

Is it the issue with the Bing Map API ? Maybe I should use the getDistance method in a different way ?


Although the distances are close to what Bing Map shows manually however not exactly the same . How come they are not the same ?

Thank You !

like image 458
CHEBURASHKA Avatar asked Jan 26 '14 03:01

CHEBURASHKA


1 Answers

If you use actual coordinates manually, the driving time seems to be identical given rounding of seconds, see test link. I get 35 minutes and your floored result is 34 minutes.

Now, about the distance. In the test link you can see it's 26.7 miles, whereas your code gives a result of 42.898 (you added the 'miles' unit there yourself!). Now, if you convert your 26.7 miles to kilometers, you get 42.9695. I would thus claim the result of .getDistance() is actually kilometers, not miles.

By looking at Route api seems to confirm it:

distanceUnit

du

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

One of the following values:

  • Mile or mi
  • Kilometer or km [default]

So the numbers you get are pretty much accurate IMO.

like image 85
eis Avatar answered Oct 13 '22 17:10

eis