Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: how to add info window to custom overlay in google maps like normal marker

srikanth reddy gongati:

I am new to google maps javascript Api.I have added Custom marker using custom Overlay in my i want to add infoWindow to custom marker.i am able to add alert using addDomListener method please find my below code

if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (pos) {
var myLatLng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
// var userObj = {}

function CustomMarker(latlng, map, imageSrc) {
this.latlng_ = latlng;
this.imageSrc = imageSrc;

// Once the LatLng and text are set, add the overlay to the map. This will
// trigger a call to panes_changed which should in turn call draw.

CustomMarker.prototype = new google.maps.OverlayView();

CustomMarker.prototype.draw = function () {
// Check if the div has been created.
var div = this.div_;
if (!div) {
// Create a overlay text DIV
div = this.div_ = document.createElement('div');
// Create the DIV representing our CustomMarker
div.className = "customMarker"

var img = document.createElement("img");
img.src = this.imageSrc;
google.maps.event.addDomListener(div, "click", function (event) {
google.maps.event.trigger(me, "click");

// Then add the overlay to the DOM
var panes = this.getPanes();

// Position the overlay
var point = this.getProjection().fromLatLngToDivPixel(this.latlng_);
console.log("ss :"+point.x)
if (point) { = point.x + 'px'; = point.y + 'px';

CustomMarker.prototype.remove = function () {
// Check if the overlay was on the map and needs to be removed.
if (this.div_) {
this.div_ = null;

CustomMarker.prototype.getPosition = function () {
return this.latlng_;
CustomMarker.prototype.setPosition = function (latlng_) {
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 15,
UserService.GetCurrent().then(function (user) {
$scope.user = user;
currentUser = user = myLatLng;
user.mission = room;
socket.emit('subscribe', user);
interval= setInterval(getNewCords, 2000);
// $interval.cancel(interval);
console.log("ssa :"+angular.toJson(interval))
var infowindow = new google.maps.InfoWindow();

socket.on('userList', function (userList) {
for (var i = 0; i markers[i].setMap(null);
for (var i = 0; i marker[userList[i].pseudoName]= new CustomMarker(new google.maps.LatLng(userList[i],userList[i].lat.lng), map, userList[i].icon)




} else {
alert('Geo Location feature is not supported in this browser.');

please find my custom marker reference custom marker

find below js fiddle credits to Alexey Zuev custom overlay example

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered

This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: how to add info window to custom overlay in google maps like normal marker


Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription