Avatar of Devain
DevainFlag for United States of America asked on

Google Maps - How do I map Markers with letters then add a polyline between each Marker using Geocoding???

How do I take this addToMap Function which ads markers to the map to do the following?

1.  Add markers assign each marker a different letter??
2.  Once All markers are added how do I draw a straight polyline from A-z??

var map;
var geocoder;
var address1='1111 gogo lane,NY';     // Want this to be marker A
var address2='222 gogo lane,NY';    // Want this to be marker  B
var address3=''333 gogo lane,NY';   // Want this be be marker C and so on for each address
Function Call
geocoder.getLocations(address1, addToMap);
geocoder.getLocations(address2, addToMap);
geocoder.getLocations(address3, addToMap);   // and so on
//  function adds the markers to the map. this basic.
// function works. what I need to do here is make it to where I can
// increment letters for each marker. Then map those points via a polyline pulling lat and lng via googles
// Geocoder.
// eg. A,B,C,D would be the markers then map a polyline along those
//  points using the geocoder to get cords automatically for the.
//  polyline.
function addToMap(response)
// Retrieve the object
      place = response.Placemark[0];
// Retrieve the latitude and longitude
      point = new GLatLng(place.Point.coordinates[1],
// Center the map on this point
      map.setCenter(point, 4);
// Create a marker
      marker = new GMarker(point);
// Add the marker to map
// Add address information to marker

Open in new window

JavaScriptWeb DevelopmentWeb Applications

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Thanks Bol

This helped alot.

One last question I Hope.

1. How would I go about using this same concept to place a polyline along the route D E and F?

Here is the code for the markers similar to the above and a link to the working page. Would like to use the same array example to place the polyline along that route.



  var addresses = new Array("Rochester,New York","Ohio","Indiana")
for (var i=0; i < addresses.length; i++) {
function(point) { 
if (!point) { 
alert(addresses[i] + " not found"); 
} else { 
map.setCenter(point, 15); 
var marker = addToMap(point,"This place","Some stuff to display in the<br>First Info Window")
	 // use arAddress[i] for the address
    // use arLetters for the marker letter

Open in new window


Partially answered my question. I am going to post a new question for the rest to keep it simple to understand

I'm glad to hear that helped.  Do you have latitude/longitude values for those points or an address?

The reason I ask is to know whether you will want to use an encoded value for each polyline or keep each geographic point (i.e. lat/lng).

If you have the lat/lng points then you would store them in an array (probably 2 dimensioned).  Javascript's object notation could probably help make this cleaner but even two arrays or an array with a split could be used to hold the values for lat and lng.  I can provide some specific code for this just let me know what you will be working with.

Let me know if you have a question about this.

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.

Thanks for the grade, the points and the fun question.  I hadn't realized this was closed as I was working on a response.  If you opened a new question for those things and would like me to take a look feel free to post the new question's URL in a comment here.  I'll be happy to look.

Thanks again for the fun question and I'll see you around.


Yes I did open a new question for the polyline part of it if you want to look at it thanks here is the question link.