Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a windows form desktop application in VB.Net. I have a web link of google maps direction, if if enter this link in web browser then the browser shows the map direction and i can easily see the route map(s), distance & time. But i want to get the distance value in numeric form, such that i can store this in a variable and the show in a textbox and then save to database.

I think i explained what i want.

can anyone help me in this regards?

Thanks.
Muhammad Asim Mughal

What I have tried:

I have tried nothing because i have no idea.
Posted
Comments
Richard MacCutchan 12-Jan-24 11:47am    
You need to use one of the Google API features; check the Google maps documentation.

1 solution

To retrieve the distance value from a Google Maps direction link in VB.NET in 5 lines, you can use the following code:


Dim directionLink As String = "YOUR_GOOGLE_MAPS_DIRECTION_LINK_HERE"
Dim webClient As New System.Net.WebClient()
Dim response As String = webClient.DownloadString(directionLink)
Dim distanceIndex As Integer = response.IndexOf("""text"":""") + 8
Dim distance As String = response.Substring(distanceIndex, response.IndexOf(""",""", distanceIndex) - distanceIndex)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900