javascript - 我需要显示一条折线,其中包含从数据库动态获取的一组点,精确地捕捉到道路

标签 javascript c# jquery google-maps-api-3

我有一条由一组从数据库动态获取的纬度和经度值组成的折线,我需要它在绘制时准确地捕捉到道路。

   $("#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 study: multi auto routes/direction with unlimited waypoints click by click 。您可以将其视为基本内容并根据您的需要进行更改。

关于javascript - 我需要显示一条折线,其中包含从数据库动态获取的一组点,精确地捕捉到道路,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41057614/

相关文章:

javascript - ImagesLoaded with Masonry, Object #<Object> 没有方法 'imagesLoaded'

c# - 如何将 JavaScript 多维数组解析为 C# 数组?

javascript - jQuery.find() IE7 错误?

javascript - jquery 这不适用于 settimeout,bug?

c# - 确定 MSBuild CoreCompile 是否将运行并调用自定义目标

c# - 网络浏览器 : sequencing activites when no DocumentCompleted is fired by a link on hosted webpage

c# - 如何以表格格式显示 SQL 数据库

javascript - 当两个不同对象的两个值匹配时,向对象添加新的键/对

javascript - 在表中选择适当的tr - jquery

javascript - 返回句子中重复字符的最大数量