我正在使用CoffeeScript来执行get
JSON请求:
$.getJSON( "http://maps.googleapis.com/maps/api/distancematrix/json?callback=?" origins: origin destinations: destinations sensor: false success: (data) -> console.log data error: (data) -> console.log data 'json' )
网址是:
http://maps.googleapis.com/maps/api/distancematrix/json?callback=?&origins=-25.8350643,28.1636066&destinations=-25.551836,%2028.423075|-25.218503,%2027.923075|&sensor=false
如果你把它放在你的浏览器中,它将返回JSON,但是ajax请求告诉我:
Uncaught SyntaxError: Unexpected token:
有任何想法吗?
解决方法
该端点不支持(JSONP)回调.
你应该采用谷歌的方式:
你应该采用谷歌的方式:
var distanceService = new google.maps.DistanceMatrixService(); distanceService.getDistanceMatrix({ origins: ['Istanbul,Turkey'],destinations: ['Ankara,travelMode: google.maps.TravelMode.DRIVING,unitSystem: google.maps.UnitSystem.METRIC,durationInTraffic: true,avoidHighways: false,avoidTolls: false },function (response,status) { if (status !== google.maps.DistanceMatrixStatus.OK) { console.log('Error:',status); } else { console.log(response); } });