0

I am trying to get city data from the xml file.
Below one is a url of XML response from which I am getting a latitude and longitude value from the XML response/file.

http://maps.googleapis.com/maps/api/geocode/xml?address=Kenya&sensor=true

and this is my JavaScript code:-

   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
function load(){
        var reg = "Kenya";
                alert(reg);
                var xml;
                $.ajax({
                  url: "http://maps.googleapis.com/maps/api/geocode/xml?address="+reg+"&sensor=true",
                  async: false,
                  dataType:'xml',
                  success: function(data)
                {
                    xml=data;
                }
            });
                var lat = $(xml).find('lat:eq(0)').text();
                var lng = $(xml).find('lng:eq(0)').text();  
                var radius = "100000";
                alert(lat);
                alert(lng);
                 $.ajax({
              url: "http://services.gisgraphy.com/geoloc/search?lat="+lat+"&lng="+lng+"&radius="+radius+"&format=json",
              async: false,
              dataType:'jsonp',
              success: function(data)
            {
                var asciiname = data.result[0].asciiName;
                console.log(asciiname);
            }
        });
            }
</script>
<body onload="load()">
</body>

with this I am trying to pass Region name in above url with lat and lang value.

http://services.gisgraphy.com/geoloc/search?lat=-0.0235590&lng=37.9061930&radius=100000.

With this url I am trying to get asciiName.
But it's not working and itss display nothing.
What I am doing wrong. Help me to solve my problem.
Thanks.

10
  • you have XML Parsing Error in second ajax. Commented May 6, 2013 at 10:06
  • You need to write proper sentences (with correct grammar) so that anybody can get the idea at first that what you want to convey? Commented May 6, 2013 at 10:10
  • @NullVoid sorry for my gammar mistake... Commented May 6, 2013 at 10:27
  • @BharatChodvadiya yes and i am try to dataType: 'jsonp', Commented May 6, 2013 at 10:28
  • I think you had also asked a similar question here and it can solve your this issue. Commented May 6, 2013 at 10:35

1 Answer 1

1

Here is your full code details. You're missing some variables like cntry_code and dataType in ajax call. If your question is solved then accept it.

<script>
    function getlg(){
            var cntry_code = 'IN';
            var reg = 'Rajkot';
            var xml;
            $.ajax({
                url: "http://services.gisgraphy.com//geocoding/geocode?address="+reg+"&country="+cntry_code+"&format=json",
                async: false,
                dataType:'jsonp',
                success: function(data){ 
                    var id = data.result[1].id;
                    console.log(id);
                    var lat = data.result[1].lat;
                    console.log(lat);
                    var lng = data.result[1].lng;  
                    console.log(lng);
                    var radius = "100000";
                    $.ajax({
                          url: "http://services.gisgraphy.com/geoloc/search?lat="+lat+"&lng="+lng+"&radius="+radius+"&format=json",
                          async: false,
                          dataType:'jsonp',
                          success: function(data)
                          {
                                for(i=0;i<data.result.length;i++)
                                {
                                    var asciiname = data.result[i].asciiName;
                                    console.log(asciiname);
                                }
                          }
                    });
                }
            });
        }
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

how can get all asciiname?
I have updated the code. I have added for loop so that you get all asciiName(s).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.