1

Here's a very simple jQuery example :

http://www.ihaols.com/geo.html

Code :

    $(function(){
        $('#btn').click(function(){
                var address = encodeURIComponent($('#k').val());
                $.get('http://maps.google.com/maps/api/geocode/json?address='+ address + '&sensor=false', function(data){
                        console.log(data);
                        var l = data.results[0].geometry.location;
                        var v = l.lat + ',' + l.lng;
                        $('#r').val(v);
                });
        });
});

But this code doesn't work in IE7/8, I've already include json2.js in it.

Sparky
  • 98,165
  • 25
  • 199
  • 285
WoooHaaaa
  • 19,732
  • 32
  • 90
  • 138
  • 3
    IE 7 and 8 [don't support CORS](http://caniuse.com/cors) and this doesn't appear to be using JSONP. – Jonathan Lonowski Sep 20 '13 at 06:33
  • 1
    @MrROY - your code is not running in any browser. In FireFox 23.0.1 on Mac, I am getting TypeError: data.results[0] is undefined – anupam Sep 20 '13 at 06:34
  • http://stackoverflow.com/q/2921745 may be worthwhile. Though, if you're heavily [concerned with rate limiting](http://stackoverflow.com/q/2921745#comment6419581_2921970), then you'll probably have to use a server-side proxy on your own origin. – Jonathan Lonowski Sep 20 '13 at 06:40
  • @MrRoy Me too faced almost similar situation ,In my case cross-domain AJAX call was the root cause. So I created one php page in my project for parse google api json with pure server side code (not used ajax). then that php page is called with ajax. – Ullas Prabhakar Sep 20 '13 at 06:57

0 Answers0