OK, so I have a polygon that is represented as an encoded polyline. I’d like to put this on a map, but can’t figure out the syntax. Here’s what I got:
setRegion = new google.maps.Polyline({
locations: "}~kvHmzrr@ba\hnc@jiu@r{Zqx~@hjp@pwEhnc@zhu@zflAbxn@fhjBvqHroaAgcnAp}gAeahAtqGkngAinc@_h|@r{Zad\y|_D}_y@swg@ysg@}llBpoZqa{@xrw@~eBaaX}{uAero@uqGadY}nr@`dYs_NquNgbjAf{l@|yh@bfc@}nr@z}q@i|i@zgz@r{ZhjFr}gApob@ff}@laIsen@dgYhdPvbIren@",
levels: "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.35
});
setRegion.setMap(map);
Which I created using the Polyline Encoder Tool. From this same page I got its use, which is:
The polyline encoding will appear in
the Encoded Polyline and Encoded
Levels fields below. Use these values
for locations and levels when you
create your google.maps.Polyline
However, the polygon does not appear. Anybody any idea what is going wrong?
UPDATE
I tried this, but get the error Uncaught TypeError: Cannot read property 'encoding' of undefined.
<!doctype html>
<html>
<head>
<title>Test</title>
<meta charset="iso-8859-1">
<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=false"></script>
<style type="text/css">
#map {width:670px;height:600px;}
</style>
<script type='text/javascript'>
function initialize() {
var myLatlng = new google.maps.LatLng(51.65905179951626, 7.3835928124999555);
var myOptions = {
zoom: 8,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map"), myOptions);
var decodedPath = google.maps.geometry.encoding.decodePath("}~kvHmzrr@ba\hnc@jiu@r{Zqx~@hjp@pwEhnc@zhu@zflAbxn@fhjBvqHroaAgcnAp}gAeahAtqGkngAinc@_h|@r{Zad\y|_D}_y@swg@ysg@}llBpoZqa{@xrw@~eBaaX}{uAero@uqGadY}nr@`dYs_NquNgbjAf{l@|yh@bfc@}nr@z}q@i|i@zgz@r{ZhjFr}gApob@ff}@laIsen@dgYhdPvbIren@");
var decodedLevels = decodeLevels("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB");
setRegion = new google.maps.Polyline({
locations: decodedPath,
levels: decodedLevels,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
setRegion.setMap(map);
}
function decodeLevels(encodedLevelsString) {
var decodedLevels = [];
for (var i = 0; i < encodedLevelsString.length; ++i) {
var level = encodedLevelsString.charCodeAt(i) - 63;
decodedLevels.push(level);
}
return decodedLevels;
}
</script>
</head>
<body onload="initialize()">
<div id="map"></div>
</body>
</html>
google.maps.geometry.encoding.decodePath(encodedPath:string)
http://code.google.com/apis/maps/documentation/javascript/reference.html#encoding
From that page:
Make sure the geometry libaray is being loaded per: http://code.google.com/apis/maps/documentation/javascript/basics.html#Libraries
Working example of the encoded polyline at: http://jsfiddle.net/ryanrolds/ukRsp/