0

Check this code

//using the url: which fetches the xml data find the link here

<GeocodeResponse>
<status>OK</status>
−
<result>
<type>locality</type>
<type>political</type>
<formatted_address>Chennai, Tamil Nadu, India</formatted_address>
−
<address_component>
<long_name>Chennai</long_name>
<short_name>Chennai</short_name>
<type>locality</type>
<type>political</type>
</address_component>
−
<address_component>
<long_name>Chennai</long_name>
<short_name>Chennai</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
−
<address_component>
<long_name>Tamil Nadu</long_name>
<short_name>TN</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
−
<address_component>
<long_name>India</long_name>
<short_name>IN</short_name>
<type>country</type>
<type>political</type>
</address_component>
−
<geometry>
−
<location>
<lat>13.0604220</lat>
<lng>80.2495830</lng>
</location>
<location_type>APPROXIMATE</location_type>
−
<viewport>
−
<southwest>
<lat>12.9734519</lat>
<lng>80.1215236</lng>
</southwest>
−
<northeast>
<lat>13.1473615</lat>
<lng>80.3776424</lng>
</northeast>
</viewport>
−
<bounds>
−
<southwest>
<lat>12.9459267</lat>
<lng>80.1487827</lng>
</southwest>
−
<northeast>
<lat>13.2340851</lat>
<lng>80.3322913</lng>
</northeast>
</bounds>
</geometry>
</result>
</GeocodeResponse> 

*In this following code ,unable to get the total no of nodes from google map, Can you please fetch the results *

$.ajax({
            type: "post",
            url: "http://maps.googleapis.com/maps/api/geocode/xml?address=chennai&sensor=false",
            dataType: "xml",
            success  : function(xmlData){
            var totalNodes = $('*',xmlData).length; // count XML nodes
            alert("This XML file has " + totalNodes);
            },
            error    : function(){
                 alert("Could not retrieve XML file.");
            }

          });

//the output will be This XML file has 20 or more nodes

4
  • In your error: function include the parameters and get the message for a bit more detail about what is exactly going wrong. Commented Feb 9, 2012 at 8:43
  • i just want to know the nodes ,, which means the counting of tags inside the xml and responses from tha url Commented Feb 9, 2012 at 9:09
  • So it is not erroring then, but always returning totalNodes as 0. Commented Feb 9, 2012 at 9:35
  • What is actually being returned, and what in that returned data are you interested in? Commented Feb 9, 2012 at 9:43

2 Answers 2

1

Your problem is this: you are trying to "POST" an ajax request to a domain that you don't own, which is impossible. You can only submit JSONP requests to external domains. The only solution you have if you want to use that endpoint is to create a proxy page on your server that will pass your request through to Google and will return the response back to your browser.

There is a native JS solution using methods provided via the Javascript API, which is detailed here: Google maps geocode API V3 not returning result in javascript function

Sign up to request clarification or add additional context in comments.

Comments

-1

You aren't passing any API keys to Google Maps which I think you need to do for Google Maps API.

1 Comment

I am using Gmap V3, so API key is not needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.