简体   繁体   中英

Google Map API - Custom Prototype marker Image not showing from today

Please see the code below, it was working fine till today morning (26-Aug-2014). after that image is not visible. all the functions are working fine.

function vehicleMarker(_description,_lat,_lng) {  

this._contentHTML = _description;   
this._markeroption = { position: new google.maps.LatLng(_lat, _lng),
    map: ObjViewmap.map,
   draggable: false
};
this.setOptions(this._markeroption);


this.updateLoc=function(_lat,_lng){
    this.setPosition(new google.maps.LatLng(_lat, _lng));       
};

google.maps.event.addListener(this, 'click', function (evt) {
    //click code here       
});  

this.disposeMarker=function(){             
    google.maps.event.clearInstanceListeners(this);       
    this.setMap(null);   
};       

this.SetVehicleImage = function (vtype) {       

    var imageurl = 'images/vehicle/' + vtype.toLowerCase() + '.png';   

    var image_a = new google.maps.MarkerImage(imageurl, new google.maps.Size(32, 32),
               new google.maps.Point(0, 0), new google.maps.Point(0, 32));
    this.setIcon(image_a);
    this.getIcon().anchor.x = 16;
    this.getIcon().anchor.y = 16;   

};


}
vehicleMarker.prototype = new google.maps.Marker();     

//----------------------------------------------------------------------------

var v=new vehicleMarker('testdesc',11.555334,76.333223);
v.SetVehicleImage('car');    

if i remove v.SetVehicleImage('car'); , still not showing google default marker.

the code will work if i remove the prototype. this was a working code, pls check.

sample code in JSFiddle http://jsfiddle.net/prajithmp/90v8vqn6/1

A new version of the API was just pushed. You are asking for version 3.9, as of the recent past you are getting 3.16. Using the "inherits" from MarkerWithLabel works:

/**
 * @param {Function} childCtor Child class.
 * @param {Function} parentCtor Parent class.
 * @private
 */
function inherits(childCtor, parentCtor) {
  /* @constructor */
  function tempCtor() {}
  tempCtor.prototype = parentCtor.prototype;
  childCtor.superClass_ = parentCtor.prototype;
  childCtor.prototype = new tempCtor();
  /* @override */
  childCtor.prototype.constructor = childCtor;
}

function MarkerX() {
// Call the parent constructor. It calls Marker.setValues to initialize, so all
// the new parameters are conveniently saved and can be accessed with get/set.
// Marker.set triggers a property changed event (called "propertyname_changed")
// that the marker label listens for in order to react to state changes.
google.maps.Marker.apply(this, arguments);       // this.setOptions(markeroption);
var _image = {
      url: "http://login.avlview.com/images/RouteFenceA.png",
      origin: new google.maps.Point(0, 0),
      anchor: new google.maps.Point(17, 34)
    };
    this.setIcon(_image);
}

inherits(MarkerX,google.maps.Marker);

var marker = new MarkerX();

updated fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM