开发者

Google Distance API

Hi I'm just wondering how do I get google api to calculate between 3 locations e.g. from point a to b to c.

I can currently get it to calculate between 2 points

var miledistance = glatlng1.distanceFrom(glat开发者_开发问答lng2, 3959).toFixed(1);


Well sounds to me you are trying to calculate the total distance between a to c by passing through b, correct? If so, you can can get the distance from a to b then from b to c and add them. Like so:

var aToB = glatlng1.distanceFrom(a, b).toFixed(1);
var bToC = glatlng1.distanceFrom(b, c).toFixed(1);
var totalDistance = aToB + bToC;

Ryan


Note that with the google distance api, you can get multiple results in one request. Therefore, the easiest way to solve your problem would be make a request for two distances, A to B and B to C, and then add the results.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜