.Net code to consume directionsAPI

3 posts / 0 new
Last post
lhidev
.Net code to consume directionsAPI

Hello,

 

We are trying to use the DirectionsAPI in .Net (Winforms) application. In order to construct the correct requests and consume the response, we need to generate the object model on .Net side and convert to json. I would appreciate if anyone can post/send sample .net (preferably vb.net) code to consume this service? 

Thanks You.


MQBrianCoakley
Sorry, I don't have any .NET
Sorry, I don't have any .NET code.

jasond
This may not help since I use

This may not help since I use XML instead of JSON, but here's the basics for the call. You would of course need to change the parameters to match what you want.

Dim loRequest As Net.HttpWebRequest
Dim loURI As Uri
Dim lsURI As String
Dim lsOutputFormat As String = "xml"
Dim loResponse As Net.HttpWebResponse

lsStartLocation = String.Format(CultureInfo.InvariantCulture, "{0},{1}", StartLatitude, StartLongitude)
lsStopLocation = String.Format(CultureInfo.InvariantCulture, "{0},{1}", StopLatitude, StopLongitude)

lsURI = "http://open.mapquestapi.com/directions/v2/route?" & _
 "key=" & lsKey & _
 "&outFormat=" & lsOutputFormat & _
 "&routeType=shortest" & _
 "&timeType=0" & _
 "&narrativeType=none" & _
 "&shapeFormat=raw" & _
 "&generalize=0" & _
 "&manMaps=false" & _
 "&fullShape=true" & _
 "&doReverseGeocode=false" & _
 "&destinationManeuverDisplay=false" & _
 "&from=" & lsStartLocation & _
 "&to=" & lsStopLocation
loURI = New Uri(lsURI)
loRequest = CType(Net.WebRequest.Create(loURI), Net.HttpWebRequest)
loResponse = CType(loRequest.GetResponse(), Net.HttpWebResponse)