Name

ST_AsEncodedPolyline — ラインストリングジオメトリから符号化したポリラインを返します。

Synopsis

text ST_AsEncodedPolyline(geometry geom, integer precision=5);

説明

Returns the geometry as an Encoded Polyline. This is a format very useful if you are using google maps

Availability: 2.2.0

Basic

SELECT ST_AsEncodedPolyline(GeomFromEWKT('SRID=4326;LINESTRING(-120.2 38.5,-120.95 40.7,-126.453 43.252)'));
        --result--
        |_p~iF~ps|U_ulLnnqC_mqNvxq`@
        

Use in conjunction with geography linestring and geography segmentize, and put on google maps

-- the SQL for Boston to San Francisco, segments every 100 KM
        SELECT ST_AsEncodedPolyline(
                ST_Segmentize(
                        ST_GeogFromText('LINESTRING(-71.0519 42.4935,-122.4483 37.64)'),
                                100000)::geometry) As encodedFlightPath;

javascript will look something like this where $ variable you replace with query result

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=geometry"></script>
<script type="text/javascript">
         flightPath = new google.maps.Polyline({
                        path:  google.maps.geometry.encoding.decodePath("$encodedFlightPath"),
                        map: map,
                        strokeColor: '#0000CC',
                        strokeOpacity: 1.0,
                        strokeWeight: 4
                });
</script>
        

関連情報

ST_LineFromEncodedPolyline, ST_Segmentize