Davide Thanks for the reply.
I am only interested in distance value. Sorry for asking again can you please suggest any site where I can see the code for reading values from the XML/xpath fusing json? On Jun 14, 1:19 pm, Davide Cremonesi <[email protected]> wrote: > I'm sorry but I'm not a .NET developer. > Seems to me that the problem is that the response schema (i.e. the json > structure) is different. You probably need to rewrite (or regenerate, if > your json/.net library does it for you) your GoogleDirections class. The > distance (in meters) is now in the pseudo path > > route/leg/distance/value > If you are only interested in distance value maybe is easier to request an > XML format and read it with an xpath expression. > > Regards, > Davide > 2010/6/14 Disha <[email protected]> > > > > > I tried code like this > > > String AddressA = "8103, Porter Ridge Ln, Manassas, VA, > > 20109"; > > String AddressB = "40294 Quailrun Ct, Lovettsville, VA 20180"; > > > //Console.Write("Enter Address A : "); > > //AddressA = Console.ReadLine(); > > > //Console.Write("Enter Address B : "); > > //AddressB = Console.ReadLine(); > > > StringBuilder sbUrl = new StringBuilder(); > > //sbUrl.Append("http://maps.google.com/maps/nav? > > output=js&oe=utf8&q="); > > sbUrl.Append("http://maps.google.com/maps/api/directions/json? > > sensor=false&"); > > sbUrl.AppendFormat("origin={0}", > > HttpUtility.UrlEncode(AddressA)); > > sbUrl.AppendFormat("&destination={0}", > > HttpUtility.UrlEncode(AddressB)); > > > Response.Write(sbUrl.ToString()); > > > Uri googleUrl = new Uri(sbUrl.ToString()); > > > HttpWebRequest request = > > (HttpWebRequest)WebRequest.Create(googleUrl); > > HttpWebResponse response = > > (HttpWebResponse)request.GetResponse(); > > using (StreamReader reader = new > > StreamReader(response.GetResponseStream())) > > { > > String gResponse = reader.ReadToEnd(); > > //Response.End(); > > GoogleDirections directions = > > JsonConvert.DeserializeObject(gResponse, > > typeof(GoogleDirections)) as GoogleDirections; > > > Response.End(); > > double myMiles = > > Convert.ToDouble(directions.Directions.Distance.meters) * 0.000621371; > > Response.Write("Json Distance : " + myMiles.ToString() + > > "<br>"); > > > } > > But it is giving me error in following line > > GoogleDirections directions = JsonConvert.DeserializeObject(gResponse, > > typeof(GoogleDirections)) as GoogleDirections; > > > Let me know what wrong I am doing? > > > On Jun 14, 11:47 am, Disha <[email protected]> wrote: > > > Thanks for reply. > > > > Can you please suggest any site or any sample code using asp.net to > > > get the distance using json? > > > > On Jun 14, 10:47 am, Davide Cremonesi <[email protected]> wrote: > > > > > Hi, > > > > formulating the request in the correct way: > > > > >http://maps.google.com/maps/api/directions/json?sensor=false&origin=C. > > .. > > > > > returns this json structure which is more clear: > > > > > { > > > > "status": "ZERO_RESULTS", > > > > "routes": [ ] > > > > > } > > > > > If you are calling it from a program, than maybe xml format will be > > > > easier to parse. > > > > > <DirectionsResponse> > > > > <status>ZERO_RESULTS</status> > > > > </DirectionsResponse> > > > > > Hope it helps, > > > > Davide > > > > > On Jun 14, 4:23 pm, Andrew Leach <[email protected]> wrote: > > > > > > On 14 June 2010 15:01, Disha <[email protected]> wrote: > > > > > > > I am using sample code from > > >http://blog.sb2.fr/post/2008/11/23/Get-Address-A-to-B-Distance-using-.... > > > > > > > I am testing following address > > > > > > > AddressA = "Calle 6 J9, CAGUAS, PR, 00726" > > > > > > AddressB = "10422 Woodlands Trail, Rowlett, TX, 75089" > > > > > > > It is not returning anything, How do I handle this? > > > > > > It's using an undocumented call to /nav: the Directions webservice > > > > > doesn't do that -- see herehttp:// > > code.google.com/apis/maps/documentation/directions/#Directions... > > > > > > Using /nav is against the Terms of Service. > > > > > > The webservice returns a status code which will tell you that it > > can't > > > > > find a route between Puerto Rico and Texas: > >http://code.google.com/apis/maps/documentation/javascript/v2/referenc... > > > > > and any code should check that before trying to use data (like the > > > > > distance) which isn't there.- Hide quoted text - > > > > > - Show quoted text -- Hide quoted text - > > > > - Show quoted text - > > > -- > > You received this message because you are subscribed to the Google Groups > > "Google Maps API" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]<google-maps-api%2bunsubscr...@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/google-maps-api?hl=en.- Hide quoted text - > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Google Maps API" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-api?hl=en.
