Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4244276
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:41:13+00:00 2026-05-21T03:41:13+00:00

I grabbed an example off of this SO question , and built my own

  • 0

I grabbed an example off of this SO question, and built my own custom Google Maps object used for deserializing the json object.

Now the code works like a champ, but I just need an explanation on why/how it works. Does the serializer “try” to match up names, or is something else going on.

What exactly is this doing?

Here’s the working code.

Imports System.Net
Imports System.Web
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Json
Imports System.Web.Script.Serialization

Namespace Utilities.Apis
    Public NotInheritable Class GoogleGeolocate


        Private Const googleUrl As String = "http://maps.googleapis.com/maps/api/geocode/json?address={0}&sensor=false"
        Private Sub New()
        End Sub

        Public Shared Function GetLatLon(ByVal address As String) As String
            ''# This is just here to prevent "placeholder" data from being submitted.
            If address = "6789 university drive" Then
                Return Nothing
            End If

            address = HttpUtility.UrlEncode(address)

            Dim url = String.Format(googleUrl, address)

            Dim request = DirectCast(HttpWebRequest.Create(url), HttpWebRequest)
            request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate")
            request.AutomaticDecompression = DecompressionMethods.GZip Or DecompressionMethods.Deflate
            Dim serializer As New DataContractJsonSerializer(GetType(GoogleResponse))
            Dim res = DirectCast(serializer.ReadObject(request.GetResponse().GetResponseStream()), GoogleResponse)

            Dim resources As GoogleResponse.Result = res.results(0)
            Dim point = resources.geometry.location.lat
            Dim latlon As New GeolocationLatLon
            With latlon
                .latitude = resources.geometry.location.lat
                .longitude = resources.geometry.location.lng
            End With

            Dim jsonSerializer = New JavaScriptSerializer

            Return jsonSerializer.Serialize(latlon)
        End Function
    End Class

    <DataContract()>
    Public Class GoogleResponse
        <DataMember()>
        Public Property results() As Result()
        <DataContract()>
        Public Class Result
            <DataMember()>
            Public Property geometry As m_Geometry
            <DataContract()>
            Public Class m_Geometry
                <DataMember()>
                Public Property location As m_location
                <DataContract()>
                Public Class m_location
                    <DataMember()>
                    Public Property lat As String
                    <DataMember()>
                    Public Property lng As String
                End Class
            End Class
        End Class

    End Class
End Namespace

And here’s the GeolocationLatLon Poco

Public Class GeolocationLatLon
    Public latitude As String
    Public longitude As String
End Class

When I call the code, it’s really quite simple.
note, this is an MVC controller, that has nothing to do “really” with the question other than to show what I’m doing

    Function GeoLocation(ByVal address As String) As ContentResult
        Return New ContentResult With {.Content = GoogleGeolocate.GetLatLon(address),
                                       .ContentType = "application/json"}
    End Function

And the final result is

{“latitude”:”50.124300″,”longitude”:”-114.4979990″}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:41:13+00:00Added an answer on May 21, 2026 at 3:41 am

    Internally, DataContractJsonSerializer maps JSON name/value pairs to an XML infoset. In fact, DataContractJsonSerializer is built on top of the XML-based DataContractSerializer and processes every JSON input and JSON output as if it were dealing with XML. There is a higher-level abstraction layer (a JSON writer and a JSON reader, as exposed via JsonReaderWriterFactory) that actually translates this XML to JSON and JSON back to internal XML.

    See this excellent overview (Mapping Between JSON and XML) to see what happens to DataContractJsonSerializer internally and how it pulls all this off.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I grabbed this snippet from another question: <script type='text/javascript' > $(document).ready(function () { $(div.content
Possible Duplicate: Can Google Maps/Places 'autocomplete' API be used via AJAX? There seems to
Right now I successfully grabbed the full element from an HTML page with this:
I grabbed this example from apples website This example seems to not run at
I grabbed this code form JCarousel and just trying to understand these lines below.
I have grabbed some XML data using this piece of jQuery: $.ajax({ type: POST,
Hoping Paul McGuire may spot this and rescue me... I have grabbed the 'regex
To better explain this I'll use Doodle Jump as an example. Assuming that the
I have a simple hide show jquery script I grabbed from an example site.
I grabbed the growl for .NET on this page http://www.growlforwindows.com/gfw/developers.aspx i ran the examples

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.