?
Solved

Google Maps - InfoWindow with Pixeloffset

Posted on 2014-04-05
1
Medium Priority
?
3,950 Views
Last Modified: 2014-04-05
I'm trying to add a pixeloffset to the google maps infowindow but the position of the infowindow will not change when clicked. I can't find out why.

This is the code I'm adding.

   pixelOffset: new google.maps.Size(60, 0),

Open in new window


This is the original code.

function iwHandle(infowindow, map, marker, style) {

	if (infoWindowDivID !== ""){
		externalDiv = document.getElementById(infoWindowDivID);
		externalDiv.innerHTML = infowindow.content;
	} else {
		infowindow.open(map,marker);
		lastInfoWindow = infowindow;
	}
}

Open in new window


function createMarker(latlng, index, html, category, icon, src, title, iconURL) {

    var myHtml;
	if ( icon === undefined ) {
      icon = category;
   }
  if (category == "pin") {

		if (markerGroups["pin"]) {

		for (var i = 0; i < markerGroups["pin"].length; i++) {
		  markerGroups["pin"][i].setMap(null);
		}
		markerGroups["pin"].length = 0;
		}

	  var image = new google.maps.MarkerImage(iconPath + category + ".png",
      new google.maps.Size(mainIconWidth, mainIconHeight),
      new google.maps.Point(0,0),
      new google.maps.Point(mainAnchorPointX, mainAnchorPointY));
	  
	  var shadow = new google.maps.MarkerImage( iconPath + category + "-shadow.png",
      new google.maps.Size(mainIconWidth, mainIconHeight),
      new google.maps.Point(0,0),
      new google.maps.Point(mainAnchorPointX, mainAnchorPointY));

	  var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        shadow: '',
        icon: image
    });
	  markerGroups["pin"].push(marker);
	  var infowindow = new google.maps.InfoWindow({
        content: html
    });
	  google.maps.event.addListener(marker, 'click', function() {
		//map.panTo(latlng);
		controlToggle("hide");
		google.maps.event.addListener(infowindow, 'closeclick', function() {
			controlToggle("show");
		});
		infowindow.open(map, marker);
    });

Open in new window

0
Comment
Question by:seopti
1 Comment
 
LVL 13

Accepted Solution

by:
duncanb7 earned 2000 total points
ID: 39980163
What is console error showing on browser debugger tool you have ? On chrome browser,
click options->tools->developer tools->console.
Please clean up all javascript syntax error first.
probably you put the line of  pixelOffset: new google.maps.Size(60, 0), without ","
as follows  and try the following portion code change.

var infowindow = new google.maps.InfoWindow({
        content: html,
 pixelOffset: new google.maps.Size(60, 0)
    });

var curmark;
 google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,this);
 curmark = this;
controlToggle("hide");
});
google.maps.event.addListener(infowindow,'closeclick',function(){
curmark.setMap(null); //removes the marker
controlToggle("show"); 
});

Open in new window


If "this" is not working, please try to replace"this" with "marker"
And take a look this link for those option and example if have time
https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple

Hope understant your question completely, if not , please pt it out

Duncan
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question