Solved

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

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
html input 8 42
How to resize a div in html 3 35
Add or delete table rows 10 53
Running a javascript project in WebStorm 2 24
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

808 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