Google地图中的自定义和航点标记 [英] Custom and waypoint markers in Google Maps

查看:93
本文介绍了Google地图中的自定义和航点标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻求一些帮助。我有以下谷歌地图代码工作正常。我需要的只是一个起点上的自定义标记:(51.943382,6.463116),在路标上没有标记。
可以这样做吗?我已经尝试了几种来自Stackoverflow的解决方案,但我对GMs代码和编程技巧的理解还不足以获得我想要的。
Thanks!

 <!DOCTYPE html> 
< html>
< head>

< meta name =viewportcontent =initial-scale = 1.0,user-scalable = no/>
< meta http-equiv =content-typecontent =text / html; charset = UTF-8/>
< title> Google Maps JavaScript API v3示例:Directions Waypoints< / title>

< link href =http://code.google.com/apis/maps/documentation/javascript/examples/default.css =stylesheettype =text / css />
< script type =text / javascriptsrc =http://maps.google.com/maps/api/js?sensor=false>
< / script>
< script type =text / javascript>
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;

函数initialize(){
directionsDisplay = new google.maps.DirectionsRenderer({
});


var myOptions = {
zoom:10,
mapTypeId:google.maps.MapTypeId.ROADMAP,
}


map = new google.maps.Map(document.getElementById(map_canvas),myOptions);
directionsDisplay.setMap(map);
calcRoute();
}

函数calcRoute(){

var waypts = [];


stop = new google.maps.LatLng(51.943571,6.463856)
waypts.push({
location:stop,
stopover:true} );
stop = new google.maps.LatLng(51.945032,6.465776)
waypts.push({
location:stop,
stopover:true});
stop = new google.maps.LatLng(51.945538,6.469413)
waypts.push({
location:stop,
stopover:true});
stop = new google.maps.LatLng(51.947462,6.467941)
waypts.push({
location:stop,
stopover:true});
stop = new google.maps.LatLng(51.945409,6.465562)
waypts.push({
location:stop,
stopover:true});
stop = new google.maps.LatLng(51.943700,6.462096)
waypts.push({
location:stop,
stopover:true});

start = new google.maps.LatLng(51.943382,6.463116);
end = new google.maps.LatLng(51.943382,6.463116);
$ b var request = {
origin:start,
destination:end,
waypoints:waypts,
optimizeWaypoints:true,
travelMode: google.maps.DirectionsTravelMode.WALKING
};

directionsService.route(request,function(response,status){
if(status == google.maps.DirectionsStatus.OK){
directionsDisplay.setDirections(response);
var route = response.routes [0];

}
});
}
< / script>
< / head>
< body onLoad =initialize()>
< div id =map_canvasstyle =width:70%; height:80%;>< / div>
< / body>
< / html>


解决方案

我只看到一个解决方案来实现这一点。

  directionsDisplay = new google.maps.DirectionsRenderer({
suppressMarkers:true
});

然后在起点处手动添加标记。

以下是 JSFiddle

以说明。



希望这有助于!


I'm looking for some help. I have below Google Map code which is working fine. Only thing I need is a custom marker on the starting point: (51.943382, 6.463116) and no markers on the waypoints. Can this be done? I have tried several solutions from Stackoverflow, but my understanding of GMs code and programming skills are not sufficient enough to get what I want. Thanks!

<!DOCTYPE html>
<html>
    <head>

        <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
        <title>Google Maps JavaScript API v3 Example: Directions Waypoints</title>

        <link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
        </script>
        <script type="text/javascript">
          var directionDisplay;
          var directionsService = new google.maps.DirectionsService();
          var map;

          function initialize() {
              directionsDisplay = new google.maps.DirectionsRenderer({
              });


              var myOptions = {
                  zoom: 10,
                  mapTypeId: google.maps.MapTypeId.ROADMAP,
              }


              map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
              directionsDisplay.setMap(map);
              calcRoute();
          }

          function calcRoute() {

              var waypts = [];


              stop = new google.maps.LatLng(51.943571, 6.463856)
                      waypts.push({
                          location:stop,
                          stopover:true});
              stop = new google.maps.LatLng(51.945032, 6.465776)
                      waypts.push({
                          location:stop,
                          stopover:true});
              stop = new google.maps.LatLng(51.945538, 6.469413)
                      waypts.push({
                          location:stop,
                          stopover:true});
              stop = new google.maps.LatLng(51.947462, 6.467941)
                      waypts.push({
                          location:stop,
                          stopover:true});
              stop = new google.maps.LatLng(51.945409, 6.465562)
                      waypts.push({
                          location:stop,
                          stopover:true});
              stop = new google.maps.LatLng(51.943700, 6.462096)
                      waypts.push({
                          location:stop,
                          stopover:true});

              start  = new google.maps.LatLng(51.943382, 6.463116);
              end = new google.maps.LatLng(51.943382, 6.463116);

              var request = {
                  origin: start,
                  destination: end,
                  waypoints: waypts,
                  optimizeWaypoints: true,
                  travelMode: google.maps.DirectionsTravelMode.WALKING
              };

              directionsService.route(request, function(response, status) {
                  if (status == google.maps.DirectionsStatus.OK) {
                      directionsDisplay.setDirections(response);
                      var route = response.routes[0];

                  }
              });
          }
        </script>
    </head>
    <body onLoad="initialize()">
        <div id="map_canvas" style="width:70%;height:80%;"></div>
    </body>
</html>

解决方案

I see only one solution to achieve that. Use the below code to remove all markers:

directionsDisplay = new google.maps.DirectionsRenderer({
    suppressMarkers: true
});

And manually add a marker at your start point.

Here is a JSFiddle to illustrate.

Hope this helps!

这篇关于Google地图中的自定义和航点标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆