Deen
Deen

Reputation: 621

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

I have lat, lng json in one variable

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

Upvotes: 1

Views: 3386

Answers (1)

Sapikelio
Sapikelio

Reputation: 2604

you have to cast your points to google.maps.latLng Points:

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

Upvotes: 4

Related Questions