0

Possible Duplicate:
Parsing Google Geo API (Reverse Geocoding) with jQuery

  $(window).load(function() {

var purl =  "http://maps.googleapis.com/maps/api/geocode/json?latlng=32.759294499999996,-97.32799089999999&sensor=false";
  $.getJSON(purl,function(result){
    $.each(result, function(i, field){
      $("#data").append(field + " ");
    });
  });

});

if you visit the url you will see results in json format. when I send this as a $.getJSON request its not returning anything under response on firebug its blank. Any thoughts ?

Community
  • 1
  • 1
cppit
  • 4,478
  • 11
  • 43
  • 68
  • 1
    getJSON will not work for cross domain requests. Example usage: https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-simple – Jason Benson Nov 08 '12 at 22:47
  • well I have a longitude and latitude and I want to get city and state using that ... the example you showed me displays a map. I dont need that. any thoughts? – cppit Nov 08 '12 at 22:49
  • I'd look at the docs or the source code. Specifically the codeAddress method in that example. I'll add the exact example google provides as an example. – Jason Benson Nov 08 '12 at 22:52
  • 1
    Are you sure that the api you are requesting from returns JSONP? All i see is JSON. – Kevin B Nov 08 '12 at 22:53

2 Answers2

0

See the reverse geocoding example here:

https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-reverse

Here is their example (minus the map):

  var geocoder;

  function initialize() {
    geocoder = new google.maps.Geocoder();
  }

  function codeLatLng(lat, lng) {
    var latlng = new google.maps.LatLng(lat, lng);
    geocoder.geocode({'latLng': latlng}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        if (results[1]) {
           alert(results[1].formatted_address);
        } else {
          alert('No results found');
        }
      } else {
        alert('Geocoder failed due to: ' + status);
      }
    });
  }

$().ready(function () {
    initialize();
    codeLatLng(32.759294499999996,-97.32799089999999);
});
Jason Benson
  • 3,371
  • 1
  • 19
  • 21
0
$.ajax({
        type : "GET",
        url : URL,
        dataType : "jsonp",
        jsonp : "jsoncallback",
        jsonpCallback : MSS,
        cache : true,
        success : function(service_data) {
            binding(service_data);

        },
        error : function(msg) {
            alert(JSON.stringify(msg));
        }
    });
gurusai
  • 153
  • 4
  • 16