简体   繁体   English

如何在Google Map API中放置多个标记并绘制路线

[英]How to place multiple markers and draw route in google map api

I have lat, lng json in one variable 我在一个变量中有lat,lng json

var path = [{"lat":"12.9247903824","lng":"77.5806503296"},{"lat":"10.9974470139","lng":"76.9459457397"}]

and I have created path from the lat lng values 我已经从经度值创建路径

var marker = new google.maps.Marker({
                position: pos,
                map: map
            });
            var flightPath = new google.maps.Polyline({
                path: path,
                geodesic: true,
                strokeColor: '#ff0000',
                strokeOpacity: 1.0,
                strokeWeight: 2,
                map: map,
                bounds: map.getBounds()
            });

It is created path from the points. 从点开始创建路径。 But Only one marker is showing. 但是只有一个标记正在显示。 For that marker have to be shown in all points(path). 对于该标记,必须在所有点(路径)中显示。

and one more, I want to get the address of all lat,lng values 另外,我想获取所有lat,lng值的地址

you have to cast your points to google.maps.latLng Points: 您必须将您的得分投到google.maps.latLng得分:

var pointsPath = [new google.maps.LatLng(12.9247903824,77.5806503296),new google.maps.LatLng(10.9974470139,76.9459457397)];

Then initialize the map like this: 然后像这样初始化地图:

 function initialize() {
      var mapOptions = {
        zoom: 3,
        center: new google.maps.LatLng(0, -180),
        mapTypeId: google.maps.MapTypeId.TERRAIN
      };


      var flightPath = new google.maps.Polyline({
        path: pointsPath,
        geodesic: true,
        strokeColor: '#FF0000',
        strokeOpacity: 1.0,
        strokeWeight: 2
      });

      flightPath.setMap(map);
    }

    google.maps.event.addDomListener(window, 'load', initialize);

Hope It helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在谷歌地图api中绘制多个标记 - How to draw multiple markers in google map api 如何使用javascript在谷歌地图中的多个标记之间绘制路线图 - How to draw Route map between multiple markers in google maps using javascript 如何在Google Maps API中的两个标记之间绘制路线? - How to draw a route between two markers in Google Maps API? 如何在v3中为Google地图标记放置多个图标? - How to place multiple icons for Google map markers in v3? Google Places API在地图上放置了多个标记,并缩放到大多数标记所在的位置 - Google places API place multiple markers on the map and zoom to where most markers are 使用回调功能在Google地图上放置多个标记 - Place multiple markers on google map with callback function 如何使用某些LatLng在Google地图上放置标记,而不是绘制多边形? - How can some LatLng be used to place markers on a Google map, but not to draw a Polygon? 如何在谷歌地图的标记之间画一条线 - How to draw a line between the markers in google map 如何使用Google Map API显示多个位置标记? - How to show multiple location markers using Google Map API? 如何在同一地图上使用带有多个标记的Google Maps API - How to use google maps API with multiple markers on the same map
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM