Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Google Maps - InfoWindow with Pixeloffset

Posted on 2014-04-05
1
Medium Priority
?
3,643 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to create an extensible mechanism for linked drop downs.
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

877 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