-
Mar 26th, 2019, 03:06 PM
#1
Thread Starter
Junior Member
[RESOLVED] encodeURIComponent
I am using the following code to obtain GeoCode coordinates.
Code:
Private Function GetAddress(ByVal StreetAddress As String, ByVal city As String, ByVal state As String, ByVal zip As String) As Address
Dim newAddress As New Address()
Dim reader As New XmlTextReader("https://maps.googleapis.com/maps/api/geocode/xml?address=" + StreetAddress + " " + city + "," + state + "&key=********")
'Handle whitespace
reader.WhitespaceHandling = WhitespaceHandling.Significant
'get node values And populate address
While (reader.Read())
If reader.Name.ToString() = "lat" Then
newAddress.Latitude = CDec(reader.ReadString().ToString())
End If
If reader.Name.ToString() = "lng" Then
newAddress.Longitude = CDec(reader.ReadString().ToString())
End If
End While
Return newAddress
End Function
When a street address contains a unit number however using the "#" such as 12 Maple #45 Google hiccups and responds with error. From what I can gather so far that is because of the # in the URL. A google forum suggested using the "encodeURIComponent. I have been unable to find any sample VB code and not sure how to properly implement it. This is way above my head at the moment and don't even know where to begin
Any help or direction would be appreciated it
Thank you
-
Mar 26th, 2019, 03:46 PM
#2
Re: encodeURIComponent
There are various options depending on what kind of project you are working on (eg: ASP.Net or Winforms), but there is a good chance that this kind of thing will work for you:
Code:
Dim StreetAddressEncoded as String = System.Net.WebUtility.UrlEncode(StreetAddress)
.
Note that you should only encode the values themselves, not the other parts of the URL (such as "&key=" etc).
Documentation for UrlEncode: https://docs.microsoft.com/en-us/dot...ramework-4.7.2
-
Mar 26th, 2019, 04:14 PM
#3
Thread Starter
Junior Member
Re: encodeURIComponent
Thanks I am getting an error URLEncode is not a member of WebUtility
-
Mar 26th, 2019, 04:58 PM
#4
Re: encodeURIComponent
Have you added the reference referred to in the linked article?
-
Mar 26th, 2019, 05:03 PM
#5
Thread Starter
Junior Member
Re: encodeURIComponent
Yes first thing I did was add the System.Net
-
Mar 26th, 2019, 05:10 PM
#6
Re: encodeURIComponent
That is the namespace, not necessarily the assembly; immediately under the namespace it says
Assemblies:
System.Runtime.Extensions.dll, System.dll, netstandard.dll
try adding the System.Runtime.Extensions.dll and see if that works.
-
Mar 26th, 2019, 06:23 PM
#7
Thread Starter
Junior Member
Re: encodeURIComponent
I dont see that reference ?
-
Mar 26th, 2019, 07:02 PM
#8
Re: encodeURIComponent
What version of Visual Studio and .Net are you using? I just created a new WinForms project with VS 2017 and I didn't need to add any references to make the code posted si work.
-
Mar 26th, 2019, 07:15 PM
#9
Thread Starter
Junior Member
Re: encodeURIComponent
It says
MS Visual Studio Express 2017
Microsoft.NET Framework Version 4.7
-
Mar 26th, 2019, 07:17 PM
#10
Thread Starter
Junior Member
Re: encodeURIComponent
It says
MS Visual Studio Express 2017
Microsoft.NET Framework Version 4.7
-
Mar 26th, 2019, 08:17 PM
#11
Thread Starter
Junior Member
Re: encodeURIComponent
You are right if I create a new Winforms project I don't need to add any references
My project was originally created on VS 2008 it upgraded when I opened it in VS 2017 so obviously something is missing as a result of the upgrade
any ideas? Copying the whole project will be a nightmare lol
-
Mar 26th, 2019, 08:18 PM
#12
Thread Starter
Junior Member
Re: encodeURIComponent
You are right if I create a new Winforms project I don't need to add any references
My project was originally created on VS 2008 it upgraded when I opened it in VS 2017 so obviously something is missing as a result of the upgrade
any ideas? Copying the whole project will be a nightmare lol
-
Mar 26th, 2019, 08:26 PM
#13
Re: encodeURIComponent
I don't think I have ever installed the Express edition of VS 2017 (in fact I didn't even realise there was one!), I know the previous express editions had various limitations so perhaps you are missing some of the web related files if you have the desktop edition installed. Then again I am guessing at this point so I could be completely wrong!
Is there a reason you are using the Express Edition rather than the Community Edition as that is free and is pretty much the full Visual Studio 2017 package?
If you open the .vbproj in notepad (or similar) for both the old and the new project there should be a list of references in there, you might be able to copy the references from the new vbproj into the old one and see if that solves the problem.
Edit: Didn't see the last post as I had too many tabs open...
Last edited by PlausiblyDamp; Mar 26th, 2019 at 08:29 PM.
-
Mar 26th, 2019, 11:30 PM
#14
Thread Starter
Junior Member
Re: encodeURIComponent
I was targeting the incorrect framework
Thank you for your help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|