I want to add a marker on click event and add it into exact location where user clicked on map.
Can't use any of the official examples which eventually return nothing.
My current module specific js code is as follows (just trying to build it step by step):
(function ($) {
Drupal.behaviors.gmapPage = {
attach: function(context, settings) {
// Get map object / instance
var map = Drupal.gmap.getMap($('.gmap-gmap').attr('id'));
// Is this available in some other way?
console.log(map); // Prints Drupal.gmap.map, but map != Drupal.gmap.map
google.maps.event.addListener(map, 'click', function (e) {
console.log(e.latLng);
});
}
};
})(jQuery);
Everything else is fine but cannot create any functionality for the map. Such an easy development task which seems so unbelievably challenging...
And this is purely for the front-end /ui - this question isn't about how to save location, load them into map etc. back-end related.
UPDATE:
I've added following script just for testing purposes:
(function ($) {
Drupal.behaviors.gmapPage = {
attach: function(context, settings) {
// Get map object / instance
var map = Drupal.gmap.getMap(settings.gmap.auto2map.id);
// Following works although e is undefined
// if 'ready' is changed to 'click' nothing happens
map.bind('ready', function (e){
console.log(e, 'map is ready');
});
}
};
})(jQuery);