我写下了以下代码:
var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng="+position.coords.latitude+","+position.coords.longitude+"&sensor=false&callback=parseMe";
console.log('URL is -- '+url);
var scr = document.createElement('script');
scr.src = url
scr.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(scr);
如何从此通话中捕获响应?
我正在回复回复。请看这张图片:http://i.imgur.com/RZAit.png
如何在变量中捕获此响应?
答案 0 :(得分:1)
如果您使用的是V3,则应使用地理编码API: http://code.google.com/apis/maps/documentation/geocoding/
API不再返回JSON-P,因此您无法使用ajax在同一域上没有代理的情况下访问它。
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ <put options here>}, callback);
结果和状态将发送到回调函数。
答案 1 :(得分:0)
我使用jQuery的getJSON()方法:http://api.jquery.com/jQuery.getJSON/,它会自动从您可以使用的响应中创建一个json对象。