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 application.now 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.
this.setMap(map);
}

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;
div.appendChild(img);
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();
panes.overlayImage.appendChild(div);
}

// Position the overlay
var point = this.getProjection().fromLatLngToDivPixel(this.latlng_);
console.log("ss :"+point.x)
if (point) {
div.style.left = point.x + 'px';
div.style.top = 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_.parentNode.removeChild(this.div_);
this.div_ = null;
}
};

CustomMarker.prototype.getPosition = function () {
return this.latlng_;
};
CustomMarker.prototype.setPosition = function (latlng_) {
this.latlng_=latlng_;
this.draw();
};
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 15,
center:myLatLng
});
UserService.GetCurrent().then(function (user) {
$scope.user = user;
currentUser = user
user.lat = 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);
}
console.log(userList[i].icon);
for (var i = 0; i marker[userList[i].pseudoName]= new CustomMarker(new google.maps.LatLng(userList[i].lat.lat,userList[i].lat.lng), map, userList[i].icon)
markers.push(marker[userList[i].pseudoName]);

}


});

})

} 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
HERE


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

×