user1261817
user1261817

Reputation: 1593

Draw line on map when button is clicked (using Google Maps API 3, Javascript)

I am using Google Maps API 3. I have a map and a button. On the map, I have two markers. When I click the button, I want to draw a line between the two markers.

Upvotes: 1

Views: 1436

Answers (1)

geocodezip
geocodezip

Reputation: 161404

Not sure why you need Ajax. With 2 markers and the google maps API v3 you can draw a straight line between them.

something like this (run when the button is clicked) should work with the correct names of marker1 and marker2:

var polyline = new google.maps.Polyline({path:[marker1.getPosition(), marker2.getPosition()});

Tested in IE on this map

with this in the address bar:

javascript:{var polyline = new google.maps.Polyline({path:[gmarkers[0].getPosition(), gmarkers[1].getPosition()], map:map});}

Upvotes: 1

Related Questions