Search code examples
javascriptgoogle-mapsgoogle-maps-api-2

Google Map Marker with custom numbering


I have a Google Maps marker function that successfully creates markers on a map like this:

 // A function to create the marker and set up the event window
  function createMarker(point,html) {
    var marker = new GMarker(point,{title:html});
    GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml(html);
    });
    return marker;
  }

Here is a tinyurl of the exiting code: http://tinyurl.com/b8f9b4l

Using this solution: Google maps: place number in marker?

I've updated this line of code but it is not numbering. What am I doing wrong?

var marker = new GMarker(point,{title:html,icon:'icon: \'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld='+ (position) +'|FF776B|000000',});

Solution

  • The icon property just needs to be the url. You don't need the extra "icon:", and you should drop the extra comma at the end (IE seems to throw an exception when it finds a dangling comma). Also, the parenthesis you don't need - but probably aren't hurting anything.

    {
    title:html,
    icon: 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=' + position +'|FF776B|000000'
    }
    

    I see where you got the idea. Idk why s/he got a point for that. The extra "icon:" messes it up.

    Try this as a test, it should make sure you don't have any problems with the variables inside the url.

    {
    title:html,
    icon: 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=4|FF776B|000000'
    }