MCPcopy Index your code
hub / github.com/googlemaps/google-maps-services-python / encode_polyline

Function encode_polyline

googlemaps/convert.py:332–363  ·  view source on GitHub ↗

Encodes a list of points into a polyline string. See the developer docs for a detailed description of this encoding: https://developers.google.com/maps/documentation/utilities/polylinealgorithm :param points: a list of lat/lng pairs :type points: list of dicts or tuples :rtype

(points)

Source from the content-addressed store, hash-verified

330
331
332def encode_polyline(points):
333 """Encodes a list of points into a polyline string.
334
335 See the developer docs for a detailed description of this encoding:
336 https://developers.google.com/maps/documentation/utilities/polylinealgorithm
337
338 :param points: a list of lat/lng pairs
339 :type points: list of dicts or tuples
340
341 :rtype: string
342 """
343 last_lat = last_lng = 0
344 result = ""
345
346 for point in points:
347 ll = normalize_lat_lng(point)
348 lat = int(round(ll[0] * 1e5))
349 lng = int(round(ll[1] * 1e5))
350 d_lat = lat - last_lat
351 d_lng = lng - last_lng
352
353 for v in [d_lat, d_lng]:
354 v = ~(v << 1) if v < 0 else v << 1
355 while v >= 0x20:
356 result += (chr((0x20 | (v & 0x1f)) + 63))
357 v >>= 5
358 result += (chr(v + 63))
359
360 last_lat = lat
361 last_lng = lng
362
363 return result
364
365
366def shortest_path(locations):

Callers 1

shortest_pathFunction · 0.85

Calls 1

normalize_lat_lngFunction · 0.85

Tested by

no test coverage detected