Javascript Parse.com Cloudcode,计算两个位置之间的行驶距离
我有一个beforeSave函数,类的一个字段是一个地质点,我想找到以前可用的数据和即将更新的数据之间的行驶距离。我知道我需要使用谷歌地图之类的服务来查找驾驶距离。但我不明白如何在云代码中使用第三方js,或者通过来自云代码的https请求调用Google directions服务。我该怎么做呢。谢谢。解决方案是使用谷歌项目的api键调用谷歌地图的REST服务 我的代码就是这样运行的Javascript Parse.com Cloudcode,计算两个位置之间的行驶距离,javascript,google-maps-api-3,parse-platform,parse-cloud-code,google-directions-api,Javascript,Google Maps Api 3,Parse Platform,Parse Cloud Code,Google Directions Api,我有一个beforeSave函数,类的一个字段是一个地质点,我想找到以前可用的数据和即将更新的数据之间的行驶距离。我知道我需要使用谷歌地图之类的服务来查找驾驶距离。但我不明白如何在云代码中使用第三方js,或者通过来自云代码的https请求调用Google directions服务。我该怎么做呢。谢谢。解决方案是使用谷歌项目的api键调用谷歌地图的REST服务 我的代码就是这样运行的 var url = "https://maps.googleapis.com/maps/api/dista
var url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins="+oldLatitude+","+oldLongitude
url = url+"&destinations="+newLatitude+","+newLongitude+"&key=YOUR_API_KEY";
Parse.Cloud.httpRequest({
url: url,
}).then(function(httpResponse) {
var distance = (JSON.parse(httpResponse.text)).rows[0].elements[0].distance.value;
response.success();
}, function(err) {
console.log(err);
response.success();
});