GoogleMaps Framework Reference
Stay organized with collections
Save and categorize content based on your preferences.
GMSPath
@interface GMSPath : NSObject <NSCopying, NSMutableCopying>
GMSPath
encapsulates an immutable array of CLLocationCooordinate2D
. All the coordinates of a
GMSPath
must be valid. The mutable counterpart is GMSMutablePath
.
-
Convenience constructor for an empty path.
Declaration
Objective-C
+ (nonnull instancetype)path;
-
Initializes a newly allocated path with the contents of another GMSPath
.
Declaration
Swift
init(path: GMSPath)
Objective-C
- (nonnull id)initWithPath:(nonnull GMSPath *)path;
-
Declaration
Swift
func count() -> UInt
Objective-C
- (NSUInteger)count;
-
Returns kCLLocationCoordinate2DInvalid
if index
>= count.
Declaration
Swift
func coordinate(at index: UInt) -> CLLocationCoordinate2D
Objective-C
- (CLLocationCoordinate2D)coordinateAtIndex:(NSUInteger)index;
-
Declaration
Swift
convenience init?(fromEncodedPath encodedPath: String)
Objective-C
+ (nullable instancetype)pathFromEncodedPath:(nonnull NSString *)encodedPath;
-
Returns an encoded string of the path in the format described above.
Declaration
Swift
func encodedPath() -> String
Objective-C
- (nonnull NSString *)encodedPath;
-
Returns a new path obtained by adding deltaLatitude
and deltaLongitude
to each coordinate
of the current path. Does not modify the current path.
Declaration
Swift
func pathOffset(byLatitude deltaLatitude: CLLocationDegrees, longitude deltaLongitude: CLLocationDegrees) -> Self
Objective-C
- (nonnull instancetype)pathOffsetByLatitude:(CLLocationDegrees)deltaLatitude
longitude:(CLLocationDegrees)deltaLongitude;
-
Returns the fractional number of segments along the path that correspond to length
,
interpreted according to kind
. See GMSLengthKind
.
Declaration
Swift
func segments(forLength length: CLLocationDistance, kind: GMSLengthKind) -> Double
Objective-C
- (double)segmentsForLength:(CLLocationDistance)length kind:(GMSLengthKind)kind;
-
Returns the length of the path, according to kind
. See GMSLengthKind
.
Declaration
Objective-C
- (CLLocationDistance)lengthOfKind:(GMSLengthKind)kind;
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-27 UTC.
[null,null,["Last updated 2025-08-27 UTC."],[[["\u003cp\u003e\u003ccode\u003eGMSPath\u003c/code\u003e is an immutable class representing an ordered sequence of geographical coordinates.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods to initialize, encode/decode, and manipulate paths (e.g., offsetting coordinates).\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eGMSPath\u003c/code\u003e allows calculating the length of the path and its segments using different measurement kinds.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can easily access the coordinates stored within the path and determine its size.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eGMSMutablePath\u003c/code\u003e is the mutable counterpart for dynamic path modifications.\u003c/p\u003e\n"]]],["`GMSPath` manages an immutable array of `CLLocationCoordinate2D`. Key actions include: creating a path (empty or from an existing one), getting the path's size or a coordinate at a specific index, initializing a path from or generating an encoded string representation. Additional methods include shifting all coordinates by a specified latitude/longitude delta, calculating segments for a given length along the path, and determining the total path length based on a defined length kind.\n"],null,["# GoogleMaps Framework Reference\n\nGMSPath\n=======\n\n @interface GMSPath : NSObject \u003cNSCopying, NSMutableCopying\u003e\n\n`GMSPath` encapsulates an immutable array of `CLLocationCooordinate2D`. All the coordinates of a\n`GMSPath` must be valid. The mutable counterpart is [GMSMutablePath](../Classes/GMSMutablePath.html).\n- `\n ``\n ``\n `\n\n ### [+path](#/c:objc(cs)GMSPath(cm)path)\n\n `\n ` \n Convenience constructor for an empty path. \n\n #### Declaration\n\n Objective-C \n\n + (nonnull instancetype)path;\n\n- `\n ``\n ``\n `\n\n ### [-initWithPath:](#/c:objc(cs)GMSPath(im)initWithPath:)\n\n `\n ` \n Initializes a newly allocated path with the contents of another `GMSPath`. \n\n #### Declaration\n\n Swift \n\n init(path: GMSPath)\n\n Objective-C \n\n - (nonnull id)initWithPath:(nonnull GMSPath *)path;\n\n- `\n ``\n ``\n `\n\n ### [-count](#/c:objc(cs)GMSPath(im)count)\n\n `\n ` \n Get size of path. \n\n #### Declaration\n\n Swift \n\n func count() -\u003e UInt\n\n Objective-C \n\n - (NSUInteger)count;\n\n- `\n ``\n ``\n `\n\n ### [-coordinateAtIndex:](#/c:objc(cs)GMSPath(im)coordinateAtIndex:)\n\n `\n ` \n Returns `kCLLocationCoordinate2DInvalid` if `index` \\\u003e= count. \n\n #### Declaration\n\n Swift \n\n func coordinate(at index: UInt) -\u003e CLLocationCoordinate2D\n\n Objective-C \n\n - (CLLocationCoordinate2D)coordinateAtIndex:(NSUInteger)index;\n\n- `\n ``\n ``\n `\n\n ### [+pathFromEncodedPath:](#/c:objc(cs)GMSPath(cm)pathFromEncodedPath:)\n\n `\n ` \n Initializes a newly allocated path from [-encodedPath](../Classes/GMSPath.html#/c:objc(cs)GMSPath(im)encodedPath). This format is described at:\n \u003chttps://developers.google.com/maps/documentation/utilities/polylinealgorithm\u003e \n\n #### Declaration\n\n Swift \n\n convenience init?(fromEncodedPath encodedPath: String)\n\n Objective-C \n\n + (nullable instancetype)pathFromEncodedPath:(nonnull NSString *)encodedPath;\n\n- `\n ``\n ``\n `\n\n ### [-encodedPath](#/c:objc(cs)GMSPath(im)encodedPath)\n\n `\n ` \n Returns an encoded string of the path in the format described above. \n\n #### Declaration\n\n Swift \n\n func encodedPath() -\u003e String\n\n Objective-C \n\n - (nonnull NSString *)encodedPath;\n\n- `\n ``\n ``\n `\n\n ### [-pathOffsetByLatitude:longitude:](#/c:objc(cs)GMSPath(im)pathOffsetByLatitude:longitude:)\n\n `\n ` \n Returns a new path obtained by adding `deltaLatitude` and `deltaLongitude` to each coordinate\n of the current path. Does not modify the current path. \n\n #### Declaration\n\n Swift \n\n func pathOffset(byLatitude deltaLatitude: CLLocationDegrees, longitude deltaLongitude: CLLocationDegrees) -\u003e Self\n\n Objective-C \n\n - (nonnull instancetype)pathOffsetByLatitude:(CLLocationDegrees)deltaLatitude\n longitude:(CLLocationDegrees)deltaLongitude;\n\n[GMSPathLength\n-------------](#/GMSPathLength)\n\n- `\n ``\n ``\n `\n\n ### [-segmentsForLength:kind:](#/c:objc(cs)GMSPath(im)segmentsForLength:kind:)\n\n `\n ` \n Returns the fractional number of segments along the path that correspond to `length`,\n interpreted according to `kind`. See [GMSLengthKind](../Enums/GMSLengthKind.html). \n\n #### Declaration\n\n Swift \n\n func segments(forLength length: CLLocationDistance, kind: ../Enums/GMSLengthKind.html) -\u003e Double\n\n Objective-C \n\n - (double)segmentsForLength:(CLLocationDistance)length kind:(../Enums/GMSLengthKind.html)kind;\n\n- `\n ``\n ``\n `\n\n ### [-lengthOfKind:](#/c:objc(cs)GMSPath(im)lengthOfKind:)\n\n `\n ` \n Returns the length of the path, according to `kind`. See [GMSLengthKind](../Enums/GMSLengthKind.html). \n\n #### Declaration\n\n Swift \n\n func length(of kind: ../Enums/GMSLengthKind.html) -\u003e CLLocationDistance\n\n Objective-C \n\n - (CLLocationDistance)lengthOfKind:(../Enums/GMSLengthKind.html)kind;"]]