您正在客户端使用距离矩阵服务。 但是 客户端(浏览器)站点不支持您尝试访问API的方式,并且这种方式无法可靠地工作。
很好,这里有一个供您使用的库: 这是客户端上的Distance Matrix
Service指南。这是一个vanilla-
js示例,请检查一下。
也许此片段将帮助您:
const matrix = new google.maps.DistanceMatrixService();matrix.getDistanceMatrix({ origins: [new google.maps.LatLng(25.7694708, -80.259947)], destinations: [new google.maps.LatLng(25.768915, -80.254659)], travelMode: google.maps.TravelMode.DRIVING,}, function(response, status) { //do something});


