Encoded Polylines-GoogleMaps/API/doc/Examples/13-EncodedPolylines-N☆E 学習帳

[ リロード ]   [ ソース ]  [ トップ | 一覧 | 単語検索 | 最新 | バックアップ | ヘルプ ]

Counter: 3818, today: 1, yesterday: 1

Encoded Polylines

http://www.google.com/apis/maps/docu­mentation/

Version 2 (2006.9新規)

The GPolyline object within a Google map denotes a line as a series of points, making it easy to use but not necessarily compact. Long and complicated lines require a fair amount of memory, and often may take longer to draw. Also, the individual segments within an unencoded polyline are drawn on a Google Map regardless of their resolution at larger zoom levels.

The Google Maps API also allows you to represent paths using encoded polylines, which specify a series of points within a GPolyline using a compressed format of ASCII characters. The encoded polyline also allows you to specify groups of zoom levels that should be ignored when drawing line segments; doing so allows you to specify how detailed a polyline should be at a given zoom level. Although more difficult to set up, encoded polylines can make your overlays draw much more efficiently.

For example, a GPolyline of 3 points (2 line segments) is normally represented as:

var polyline = new GPolyline([
  new GLatLng(37.4419, -122.1419),
  new GLatLng(37.4519, -122.1519),
  new GLatLng( 37.4619, -122.1819)
], "#FF0000", 10);
map.addOverlay(polyline);

An encoded GPolyline of these same points appears below (for now, don't worry about particulars of the encoding algorithm).

var encodedPolyline = new GPolyline.fromEncoded([
  color: "#FF0000",
  weight: 10,
  points: "yzocFzynhVq}@n}@o}@nzD",
  levels: "BBB",
  zoomLevel: 32,
  numLevels: 4
]);
map.addOverlay(encodedPolyline);

zoomFactor ではなく zoomFactor なのでは?

There are two things to notice about this code.

  1. First, the series of points is represented as a series of ASCII characters in the encoded polyline, while familiar latitude and longitudes are used in the basic GPolyline. The algorithm for creating these points as a series of encoded ASCII values is documented here. This algorithm is needed if you wish to calculate encoded polylines on the fly via a server process, for example. However, if you just wish to convert existing points given latitudes and longitudes, you can use our interactive utility.
  2. Second, the encoded polyline also allows you to specify the maximum zoom level for each line segment to draw itself on a Google map. If a point is not shown on a higher zoom level, the path is simply drawn from the previous displayable point to the next displayable point. Note that this feature is not available within non-encoded GPolylines and is especially useful for allowing fast drawing at high zoom levels, where the details of some line segments may not be relevant. For example, an encoded polyline representing a drive from New York City to Chicago should not care about the line segments representing particular streets in Manhattan when the map is zoomed out to the state level.

Interactive Polyline Encoder Utility
http://www.google.com/apis/maps/docu­mentation/polylineutility.html