This project is read-only.
WsdlService - Bing Map rounting service

Category:
TypeProviders.Others
Description: Using Bing Map API routing service to calculate the driving distance between two addresses. For more information, please goto http://www.microsoft.com/maps/developers/mapapps.aspx. Please make sure you setup the correct credential.
Code:

type G = Microsoft.FSharp.Data.TypeProviders.WsdlService< ServiceUri=@"http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc?wsdl">

type R = Microsoft.FSharp.Data.TypeProviders.WsdlService< ServiceUri=@"http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc?wsdl">

type GeoCommon = G.ServiceTypes.dev.virtualearth.net.webservices.v1.common
type Geocode = G.ServiceTypes.dev.virtualearth.net.webservices.v1.geocode
type RouteCommon = R.ServiceTypes.dev.virtualearth.net.webservices.v1.common
type Route = R.ServiceTypes.dev.virtualearth.net.webservices.v1.route

let WsdlBingMap() =
let geoClient = G.GetHttpGeocodeServiceClient()
let geoReq = new Geocode.GeocodeRequest()
//To sign up for a Bing service developer account at http://msdn.microsoft.com/en-us/library/gg605201.aspx
geoReq.Credentials <- new GeoCommon.Credentials(ApplicationId = Utils.BING_APP_ID)

geoReq.Query <- "One Microsoft Way, Redmond, WA 98052"
let response = geoClient.Geocode(geoReq)
let work = response.Results.[0]

geoReq.Query <- "400 Broad St Seattle, WA 98109"
let response2 = geoClient.Geocode(geoReq)
let home = response2.Results.[0]

let startPoint = new Route.Waypoint()
startPoint.Location <- new RouteCommon.Location(Latitude = work.Locations.[0].Latitude,
Longitude = work.Locations.[0].Longitude)
let endPoint = new Route.Waypoint()
endPoint.Location <- new RouteCommon.Location(Latitude = home.Locations.[0].Latitude,
Longitude = home.Locations.[0].Longitude)

let routReq1 = new Route.RouteRequest(Waypoints = [|startPoint; endPoint|])
routReq1.Credentials <- new RouteCommon.Credentials(ApplicationId = Utils.BING_APP_ID)

printfn "Driving Distance = %A (miles)" (R.GetHttpRouteServiceClient().CalculateRoute(routReq1).Result.Summary.Distance)

// sample output
// Driving Distance = 22.998 (miles)
Execution Result:
Driving Distance = 22.998 (miles)


Last edited Mar 1, 2012 at 8:10 PM by ttliu2000, version 6

Comments

No comments yet.