wajeeh wajeeh - 1 month ago 20
iOS Question

Is there any way to check if `EncodedPath` string is valid for `GMSPath` in GoogleMaps on iOS swift?

I have a code that will display many

Polygon
s on the map, This is my code:

let path = GMSMutablePath(fromEncodedPath: path_str)
let polygon = GMSPolygon(path: path)
polygon.geodesic = true

polygon.map = pnlMap


This snippet work correct if the
path_str
variable in the correct format.

But if there is an error in the format of
path_str
the app will crash.

I tried the following methods:

if let path = GMSMutablePath(fromEncodedPath: path_str) {
// mycode
}


Also:

do {
let path = try GMSMutablePath(fromEncodedPath: path_str)
} catch ()...


I didn't reach to any correct solution.

I couldn't find a way to handle this exception.


Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFString characterAtIndex:]: Range or index out of bounds'
*** First throw call stack:
(...)

Answer

They fixed this issue in the new: version 2.1

GMSPath initFromEncodedPath now returns nil for invalid input (previously invalid input could result in a crash). (Issue 10162.)

Now if the Encoded Path string is wrong, the GMSPath path variable will be nil.

Comments