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 8189813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:24:34+00:00 2026-06-07T03:24:34+00:00

I am trying to call the Google Maps geocoding API, to get a formatted

  • 0

I am trying to call the Google Maps geocoding API, to get a formatted address from a lat/long pair, and then log it to the console. I am trying to get the first ‘formatted_address’ item that gets returned for a given location.
I am simple unable to extract that item from the JSON, I have no idea why. The line of code needed to extract the data would be greatly appreciated.

The javascript:

//Gets the current location of the user
function getLocation()
{
    if (navigator.geolocation)
    {
        navigator.geolocation.getCurrentPosition(showPosition);
    }

}

function showPosition(position)
{
    var latitude = position.coords.latitude;
    var longitude = position.coords.longitude;

    $.ajax({
        type: "POST",
        url: "ReportIncident.aspx/ReverseGeocode",
        data: "{latitude:" + latitude + ",longitude:" + longitude + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (returnedData)
        {
         // console.log(/****formatted_address Here Please****/);
        }
    });
}

The C#:

        [WebMethod]
        public static string ReverseGeocode(decimal latitude, decimal longitude)
        {
            // Create the web request  

            string url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + latitude + "," + longitude +
                         "&sensor=true";
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

            // Get response  
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                // Get the response stream  
                StreamReader reader = new StreamReader(response.GetResponseStream());

                // Console application output  
                return reader.ReadToEnd();
            }
        }
  • 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-06-07T03:24:36+00:00Added an answer on June 7, 2026 at 3:24 am

    Your JSON is escaped because you’re returning a string from your WebMethod, and not letting the built in JavascriptSerializer do it’s thing.

    roughly, you’re seeing this:

    "\{ /*data*/ \}"
    

    instead of this:

    { /*data*/ }
    

    You can fix this by running the returned string through eval() but note that I’m not recommending it… just saying you can

    EDIT:

     $.ajax({
        type: "POST",
        url: "ReportIncident.aspx/ReverseGeocode",
        data: "{latitude:" + latitude + ",longitude:" + longitude + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (returnedData)
        {
            var realReturnedData = eval(returnedData.d);
            //realReturnedData now has the google maps data structure you're expecting
        }
    });
    

    Again… eval is evil (if you don’t 100% trust the source). I would recommend returning a different data type from your webmethod…

    EDIT 2:

    [WebMethod]
    public static MyClass ReverseGeocode(decimal lat, decimal long) {
       MyClass obj = new MyClass();
       //do stuff
       return obj;
    }
    

    But my real question is why are you doing this with a webservice call to your server? You can directly do geocoding from Javascript to google’s API https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-reverse

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

Sidebar

Related Questions

I'm trying to call data from the Google Calendar API with help from this
I'm trying to make a jQuery $.getJSON call to the Google Maps Geocoding webservice
Im trying out the Google Maps API Geocoding feature.The map loads fine, but im
I'm trying to get coordinates of address from google map with Classic Asp. When
I'm trying to call the google.maps.event.addListener from a link. Here is the code I
I'm trying to make an external call to the google maps application on the
I've created a map using google maps v3 api for GWT. I'm trying to
I am new with google maps api. I took some sample from the manual
Trying to write a simple call to google's JSON stock ticker API. I would
I am trying to call google maps geocode and am following the example on

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.