-1
私はGoogleのAPIからの二つの異なる方法で2点P1、P2間の距離を見つけようとしています...私に異なる結果を与えるここで Googleの距離API
です次のようにこの差がある理由をいくつかのいずれかが私を説明することができ、コード...var directionsService = new google.maps.DirectionsService();
var p1 = new google.maps.LatLng(45.463688, 9.18814);
var p2 = new google.maps.LatLng(46.0438317, 9.75936230000002);
var request = {
origin: p1,//'Melbourne VIC', // a city, full address, landmark etc
destination: p2,// 'Sydney NSW',
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
console.log(response.routes[0].legs[0].distance.value/1000); // the distance in metres
//console.log(response.routes[0].legs[0].duration.value);
}
else {
// oops, there's no route between these two locations
// every time this happens, a kitten dies
// so please, ensure your address is formatted properly
}
console.log(calcDistance(p1, p2));
//if(!(parseFloat("hello"))) console.log(parseFloat("12.222"));
//calculates distance between two points in km's
function calcDistance(p1, p2) {
return (google.maps.geometry.spherical.computeDistanceBetween(p1, p2)/1000).toFixed(2);
}
});
私は 103.847は、2番目のログ
のための最初のログ 78.35 // // ...のための出力を取得していますそこに.... ....
ああ...私はそれを持っていた....... –
もう1つの疑問...私は次のライブラリを使用しています... ...ここで私はApi Keyについて言及していません....しかし、Googleの開発者サイトではapiリクエストを10/secと2500/dayに制限しました...これまでは何の問題もありませんでした....私がApi Keyについて言及しなければならないことを教えてください... –