如何查找Google Maps路径的长度

时间:2014-04-17 20:56:16

标签: ios google-maps google-maps-sdk-ios

我正在使用适用于iOS的Google Maps SDK并使用GMSMutablePath对象创建了一条路线。在 API文档中,它说它有一个名为lengthOfKind的函数来计算路径的长度,但它需要一个GMSLengthKind类型的对象。

(CLLocationDistance) lengthOfKind:      (GMSLengthKind)     kind    
Returns the length of the path, according to kind.  
See GMSLengthKind.

但是,文档中没有提到GMSLengthKind,我似乎无法找到任何对输入有意义的内容。有没有人知道inout应该是什么,或者是否有另一种方法来计算路径的长度?

This is the link which I have consult

2 个答案:

答案 0 :(得分:2)

// coord是一个坐标数组

GMSMutablePath path = [[GMSMutablePath alloc] init];

for (NSString * row in coord) {
    NSArray *array = [row componentsSeparatedByString:@"|"];
    double lat = [[array objectAtIndex: 0] doubleValue];
    double lon = [[array objectAtIndex: 1] doubleValue];
    [path addCoordinate:CLLocationCoordinate2DMake(lat, lon)];
}
// Geodesic length, in meters, along geodesic segments
NSLog(@"Lenght Length Projected=%f",[path lengthOfKind:kGMSLengthProjected]);

// Rhumb length, in meters, along rhumb (straight line) segments
NSLog(@"Lenght Length Rhumb=%f",[path lengthOfKind:kGMSLengthRhumb]);

// Length in projected space, along rhumb segments.
NSLog(@"Lenght Length Geodesic=%f",[path lengthOfKind:kGMSLengthGeodesic]);

答案 1 :(得分:1)

GMSLengthKind在GMSPath.h中定义:

/**
 * kGMSEquatorProjectedMeter may be useful when specifying lengths for segment in "projected" units.
 * The value of kGMSEquatorProjectedMeter, 1/(pi * EarthRadius), represents the length of one meter
 * at the equator in projected units. For example to specify a projected length that corresponds
 * to 100km at the equator use 100000 * kGMSEquatorProjectedMeter.
 * See [GMSPath segmentsForLength:kind:], [GMSPath lengthOfKind:] and kGMSLengthProjected.
 */
extern const double kGMSEquatorProjectedMeter;

/**
 * GMSLengthKind indicates the type of a length value, which can be geodesic (in meters), rhumb
 * length (in meters) and projected length (in GMSMapPoint units).
 */
typedef enum {
  /*
   * Geodesic length, in meters, along geodesic segments. May be useful, for example, to specify
   * lengths along the the trajectory of airplanes or ships.
   */
  kGMSLengthGeodesic,

  /*
   * Rhumb length, in meters, along rhumb (straight line) segments. May be useful, for example, to
   * draw a scale bar on a map. The visual size of a segment of a given length depens on the
   * latitude.
   */
  kGMSLengthRhumb,

  /*
   * Length in projected space, along rhumb segments. Projected length uses the same units as
   * GMSMapPoint - the Earth equator circumference has length 2. It is possible to specify projected
   * length in units corresponding to 1 meter at the equator by multiplying with
   * kGMSEquatorProjectedMeter, equal to 1/(pi * EarthRadius).
   *
   * Projected length may be useful, for example, to specify segments with the same visual length
   * regardless of latitude.
   */
  kGMSLengthProjected
} GMSLengthKind;