gpt4 book ai didi

google-maps - 谷歌地图 : display an encoded polyline

转载 作者:行者123 更新时间:2023-12-03 04:16:29 48 4
gpt4 key购买 nike

好的,我有一个表示为编码折线的多边形。我想把它放在 map 上,但无法弄清楚语法。这是我得到的:

  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);

我使用 Polyline Encoder Tool 创建的。从同一页面我得到了它的用法,即:

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

但是,多边形并未出现。有人知道出了什么问题吗?

更新

我尝试了此操作,但收到错误Uncaught TypeError:无法读取未定义的属性“编码”

<!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

从该页面:

var decodedPath = google.maps.geometry.encoding.decodePath(encodedPolyline);
var decodedLevels = decodeLevels(encodedLevels);

// Decode an encoded levels string into an array of levels.
function decodeLevels(encodedLevelsString) {
var decodedLevels = [];

for (var i = 0; i < encodedLevelsString.length; ++i) {
var level = encodedLevelsString.charCodeAt(i) - 63;
decodedLevels.push(level);
}

return decodedLevels;
}

确保几何库正在加载:http://code.google.com/apis/maps/documentation/javascript/basics.html#Libraries

编码折线的工作示例:http://jsfiddle.net/ryanrolds/ukRsp/

关于google-maps - 谷歌地图 : display an encoded polyline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5930630/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com