Skip to content

Latest commit

 

History

History
46 lines (39 loc) · 1.91 KB

File metadata and controls

46 lines (39 loc) · 1.91 KB

Encode / decode the path

Paths within the cordova-googlemaps-plugin are often specified as an Array of LatLng objects. However, passing around such an array is often bulky. You may instead use Google's polyline encoding algorithm to compress a given path, which you can later decompress through decoding.

  • encodePath(Array.<LatLng>)

    The static method encodePath() encodes the given path.

  • decodePath(String [, precision])

    To decode an encoded path, simply call decodePath() passing the method the encoded string.

Example: encodePath()

var GORYOKAKU_POINTS = [
  new plugin.google.maps.LatLng(41.79883, 140.75675),
  new plugin.google.maps.LatLng(41.799240000000005, 140.75875000000002),
  new plugin.google.maps.LatLng(41.797650000000004, 140.75905),
  new plugin.google.maps.LatLng(41.79637, 140.76018000000002),
  new plugin.google.maps.LatLng(41.79567, 140.75845),
  new plugin.google.maps.LatLng(41.794470000000004, 140.75714000000002),
  new plugin.google.maps.LatLng(41.795010000000005, 140.75611),
  new plugin.google.maps.LatLng(41.79477000000001, 140.75484),
  new plugin.google.maps.LatLng(41.79576, 140.75475),
  new plugin.google.maps.LatLng(41.796150000000004, 140.75364000000002),
  new plugin.google.maps.LatLng(41.79744, 140.75454000000002),
  new plugin.google.maps.LatLng(41.79909000000001, 140.75465),
  new plugin.google.maps.LatLng(41.79883, 140.75673)
];
var encodedPath = plugin.google.maps.geometry.encoding.encodePath(GORYOKAKU_POINTS);
alert(encodedPath);

Example: decodePath()

var encodedPolygon = "uyb~FupbzYqAoK|H{@~FaFjCxInFdGkBlEn@|FeEPmA|EaGsDiIUr@_L";
var precision = 5; //option
map.addPolygon({
    'points': plugin.google.maps.geometry.encoding.decodePath(encodedPolygon, precision),
    'strokeColor' : '#AA00FF',
    'strokeWidth': 5,
    'fillColor' : '#880000'
});