Results 1 to 14 of 14

Thread: [RESOLVED] encodeURIComponent

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2018
    Posts
    29

    Resolved [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

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2018
    Posts
    29

    Re: encodeURIComponent

    Thanks I am getting an error URLEncode is not a member of WebUtility

  4. #4
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: encodeURIComponent

    Have you added the reference referred to in the linked article?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2018
    Posts
    29

    Re: encodeURIComponent

    Yes first thing I did was add the System.Net

  6. #6
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    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.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2018
    Posts
    29

    Re: encodeURIComponent

    I dont see that reference ?

    Name:  VB2017.jpg
Views: 2150
Size:  26.9 KB

  8. #8
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    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.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Feb 2018
    Posts
    29

    Re: encodeURIComponent

    It says
    MS Visual Studio Express 2017
    Microsoft.NET Framework Version 4.7

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Feb 2018
    Posts
    29

    Re: encodeURIComponent

    It says
    MS Visual Studio Express 2017
    Microsoft.NET Framework Version 4.7

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Feb 2018
    Posts
    29

    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

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Feb 2018
    Posts
    29

    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

  13. #13
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    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.

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Feb 2018
    Posts
    29

    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
  •  



Click Here to Expand Forum to Full Width