English 中文(简体)
Adding a custom icon to a google map
原标题:

I need a hand adding a custom icon to some Google Maps javascript.

Code below for your reference:

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);
问题回答

None of the google maps API pages seem to be working but this may help any body with similar problem

// Create our "tiny" marker icon
var centreicon = new GIcon();
centreicon.constructor
centreicon.image = "http://maps.google.com/mapfiles/kml/pal3/icon31.png ";
centreicon.shadow = "http://maps.google.com/mapfiles/kml/pal3/icon31s.png ";
centreicon.iconSize = new GSize(12, 20);
centreicon.shadowSize = new GSize(22, 20);
centreicon.iconAnchor = new GPoint(6, 20);
centreicon.infoWindowAnchor = new GPoint(5, 1);

.......your code to create map then

           var marker = new GMarker(point, centreicon);

           map.addOverlay(marker);




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签