使用gmap3获取位置并绘制到已知位置的路线 - 需要一些微调

时间:2012-08-16 15:47:09

标签: javascript jquery html google-maps jquery-gmap3

我正在尝试使用gmap3来完成上述操作,但遇到了困难。我可以让“地图”显示并在上面贴上标记。我仍然掌握了javascript,我确信我的一些语法已经关闭,这显然无济于事。

我是否正确地使用地理定位来获取用户的位置,然后将路线绘制到预定义的位置?

道歉的语法不正确 - 我发现在使用JS时很难保留括号。

我正在使用可在此处找到的示例:http://gmap3.net/api/add-directions-renderer.html

<script type="text/javascript">
       $(function () {
        //get the user's location
        function getLocation(){
            $('#map').gmap3({ 
              action : 'geoLatLng',
              callback : function(latLng){
                if (latLng){
                  $(this).gmap3({
                    action: 'addMarker', 
                    latLng:latLng
                  },
                  "autofit");
                } 
              }
            });
        }
        //plot directions
        function plotRoute() {
          $('#map').gmap3({
            action: 'getRoute',
            options:{
              origin: 'latLang',
              destination: 'Tallaght Business Park, Dublin, Ireland'
              travelMode: google.maps.DirectionsTravelMode.DRIVING
            },
            callback: function(results){
              if (!results) return;
              $(this).gmap3({
                action: 'init',
                zoom: 13,
                mapTyprId: google.maps.MapTypeId.ROADMAP,
                streetViewControl: true
              },
              action: 'addDirectionsRenderer',
              options: {
                preserveViewPort: true,
                draggable: true,
                directions: results
              }
              );
            }
          });
        }
      });
    </script>

放在这个div中

<div class="gmap3" id="map"></div>

0 个答案:

没有答案