views:

285

answers:

1

Hi,

I'm not a javascript guru, so I need a hand adding a custom icon to some google maps javascript.

Code below for your reference.

All good things P

function populateMap() {
 var map = new GMap2(document.getElementById("map"));
 map.setCenter(new GLatLng(55.915832522285235, -3.5911989212036133), 10);
 map.setUIToDefault();



 var points = new Array(5);

  points[1] = [55.992602,-3.92968,'<div class="infoContainer"><h2><a href="#">Mayfield Drive, Longcroft, Bonnybridge<\/a><\/h2><p class="address">{locations_address}<\/p><\/div>'];



  points[2] = [55.9471382,-3.9729174,'<div class="infoContainer"><h2><a href="#">Oakwood Cumbernauld<\/a><\/h2><p class="address">{locations_address}<\/p><\/div>'];



  points[3] = [55.933873,-3.12406,'<div class="infoContainer"><h2><a href="#">Wauchope Square, Edinburgh<\/a><\/h2><p class="address">{locations_address}<\/p><\/div>'];



  points[4] = [55.843728,-3.95258,'<div class="infoContainer"><h2><a href="#">Gibb Street, Chapelhall<\/a><\/h2><p class="address">{locations_address}<\/p><\/div>'];



  points[5] = [55.854559,-4.000543,'<div class="infoContainer"><h2><a href="#">Paddock Street, Sikeside<\/a><\/h2><p class="address">{locations_address}<\/p><\/div>'];




 for(var i=1; i < points.length; i++) {
  var point = new GLatLng(points[i][0],points[i][1]);
  var windowInfo = points[i][2];
  var marker = createMarker(point,windowInfo);
  map.addOverlay(marker);
 }
}

    function createMarker(point, overlayText) {
 var marker = new GMarker(point);
 GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(overlayText);});
 return marker;
}

    function addLoadEvent(func) {
 var oldonload = window.onload;
 if (typeof window.onload != 'function') {
  window.onload = func;
 } else {
  window.onload = function() {
   if (oldonload) {
    oldonload();
   }
   func();
  }
 }
}

addLoadEvent(populateMap);
A: 

http://code.google.com/apis/maps/articles/customicons.html

http://groups.google.com/group/google-maps-api/web/examples-tutorials-custom-icons-for-markers

Dmitry
ThanksI've looked at these, but not too sure where i'm to integrate the var myIcon = new GIcon(G_DEFAULT_ICON); into my code.That's where i need the assistance.Thanks
mathalete
When you create an instance of GMarker, you can pass a second parameter, GMarkerOptions. Its 'icon' property will contain your custom GIcon. It is quite clearly written in a code sample in the official Maps API docs: http://code.google.com/apis/maps/documentation/overlays.html#Custom_Icons
Dmitry