Solved

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

Posted on 2012-12-27
2
1,934 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 500 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

688 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