![](/img/trans.png)
[英]How to make Google Maps V3 polyline snap to road from given points?
[英]I need to show a Polyline with set of points taken dynamically from the DB exactly snap to road
我有一条折线,该折线由一组从数据库动态获取的纬度和经度值组成,我需要它才能在绘制时精确地捕捉到道路上。
$("#btnClk")
.button()
.click(function (event) {
// event.preventDefault();
var vanselect = document.getElementById("svanid").value;
var vanftdt = document.getElementById("ResDt").value;
if ((vanselect.trim() != "") && (vanftdt.trim() != "")) {
$.post("VanRoute.aspx", {
vanno: vanselect,
vandt: vanftdt
}, function (data, status) {
alert("Request In process, Please wait.");
var first = data.split('~')[0];
var second = data.split('~')[1];
var vanlocj = JSON.parse(first);
var vanlocjson = JSON.parse(second);
for (var i = 0; i < vanlocjson.length; i++) {
var vanlat, vanlon = "";
vanlat = vanlocjson[i].LAT;
vanlon = vanlocjson[i].LON;
在此之后,我如何才能进一步将折线精确地捕捉到道路上
我已经在函数初始化中创建了折线叠加层,该叠加层将在页面加载时起作用。
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(12.860472, 77.664017),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map1 = new google.maps.Map(document.getElementById("map"), mapOptions);
// directionRenderer.setMap(map1);
// directionRenderer.setOptions({
// draggable: true
//});
poly = new google.maps.Polyline({
strokeColor: '#0000ff',
strokeOpacity: 1.0,
strokeWeight: 3
});
poly.setMap(map1);
}
google.maps.event.addDomListener(window, 'load', initialize);
});
在这里,我举了一个示例,说明如何使用方向服务克服路点限制: Gmap研究:具有无限路点的多路自动路线/方向 。 使您可以将其作为基本知识并将其更改为您的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.