?
Solved

InfoWindow Auto-Open on Google Maps API v3, not auto panning

Posted on 2012-12-27
2
Medium Priority
?
1,981 Views
Last Modified: 2012-12-29
Hello,

I am trying to implement an infowindow that automatically opens on pageload using google maps v3 API.  The infowindow opens as expected, however the window ends up out of the screen of the map.  I have looked in to modifying the height, however that does not really solve the problem (or work).  According to the documentation the infowindow is supposed to autopan by default, however it is not.  I have even tried to set that parameter to true and that does not have an impact either.

Here is the page I am having issues with:  http://www.thelocalgolfer.com/mobile/course_info_display.php?course=21913

Thanks in advance for your help.
0
Comment
Question by:neilsav
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 2000 total points
ID: 38723738
Yes, it's supposed to auto pan but Google Maps leave a ton of padding around markers. If the map is too small to fit the marker's padding and the info window it will not auto pan to fit the info window.

May I suggest using an infoBox instead of an info window. you have much more control over shape and positioning and they take up less room. Here's a sample:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>

<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> 
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>
<script type="text/javascript">
var map;

function initialize() {

  var myLatlng = new google.maps.LatLng(26.5921053, -81.6567014);

  var mapOptions = {

    zoom: 14,

    center: myLatlng,

    mapTypeId: google.maps.MapTypeId.ROADMAP

  }



  map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);



  // Add 5 markers to the map at random locations.

 

var marker = new google.maps.Marker({

	position: myLatlng, 

	map: map

}); 

var boxText = document.createElement("div");
		boxText.style.cssText = "border: 1px solid black; margin-top: 8px; background: white; padding: 5px;";
		boxText.innerHTML = "Hello World!";

		var myOptions = {
			 content: boxText
			,disableAutoPan: false
			,maxWidth: 0
			,pixelOffset: new google.maps.Size(-140, 0)
			,zIndex: null
			,boxStyle: { 
			  background: "url('http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/tipbox.gif') no-repeat"
			  ,opacity: 1
			  ,width: "280px"
			 }
			,closeBoxMargin: "10px 2px 2px 2px"
			,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
			,infoBoxClearance: new google.maps.Size(1, 1)
			,isHidden: false
			,pane: "floatPane"
			,enableEventPropagation: false
		};
		google.maps.event.addListener(marker, "click", function (e) {
			ib.open(theMap, this);
		});

		var ib = new InfoBox(myOptions);

		ib.open(map, marker);   

  }
</script>
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0; padding: 0 }
  #map_canvas { height:270px;width:458px }
</style>
</head>
<body onLoad="initialize()">
<div id="map_canvas"></div>
</body>
</html>

Open in new window

0
 
LVL 1

Author Comment

by:neilsav
ID: 38725794
Thanks - I  infobox is definitely a good option.  I decided to use pixelOffset: new google.maps.Size(0, 25), to make the window fit in to the map size.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

764 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