小型Google Maps Infowindow - 小于200px

时间:2010-06-29 11:35:19

标签: google-maps google-maps-api-3

我有一个宽度为225的map_canvas。

我希望我的信息框小于此(例如150 px)。

这可能吗?我尝试了maxWidth并添加了样式,但似乎没有任何效果。

屏幕(在imgshack上)可以在下面找到:alt text http://img121.imageshack.us/img121/8317/gmaps.png

另外, 我正在使用谷歌地图的v3

使用Javascript:

var results_coods;
var map_2;
var marker_2;
var infowindow_2;

function call_gmap()
{
if($('#map_text').attr('lat')){

    var lat = Number($('#map_text').attr('lat').replace(",","."));
    var lng = Number($('#map_text').attr('long').replace(",","."));
    initialize(lat,lng);
    /*
    var lat= '51.0153389';
    var lng = '2.7253832';  
    */

}
}

function initialize(lat,lng) {

    var latlng = new google.maps.LatLng(lat,lng);
    var myOptions = {
        zoom: 13,
        center: latlng,
        disableDefaultUI: true,
        navigationControl: true,
        navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
        draggable: false,
        scaleControl: false,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

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

var infowindow = new google.maps.InfoWindow({
    content: $('#map_text').html(),
    maxWidth: 150
});

var image = 'beachflag.png';
var marker = new google.maps.Marker({
    position: latlng, 
    map: map
});
infowindow.open(map,marker);
google.maps.event.addListener(
marker, 'click', function() {
   infowindow.open(map,marker);

}); 
google.maps.event.trigger(map, 'resize');
map.setZoom( map.getZoom() );

}



function GcodeAddress() 
{
    var map;
    geocoder = new google.maps.Geocoder();
    var address = $('#map_address').html();

     if (geocoder) {
      geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            var myOptions = {
                zoom: 13,
                center: results[0].geometry.location,
                navigationControl: false,
                scaleControl: false,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };

              var infowindow = new google.maps.InfoWindow({
              content: $('#map_text').html()
              });

             map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
            results_coods = results[0].geometry.location;
            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                map: map, 
                position: results[0].geometry.location
            });
            infowindow.open(map,marker);
            google.maps.event.addListener(
            marker, 'click', function() {
                infowindow.open(map,marker);
            }); 

            google.maps.event.trigger(map, 'resize');

            marker_2 = marker;
            map_2 = map;
           infowindow_2 = infowindow;
        } else {
          alert("Geocode was not successful for the following reason: " + status);
        }
      });
    }


}
function resizeMap()
{
    //hiervan komt 1 error, de andere van infowindow
    google.maps.event.trigger(map_2, 'resize');
    map_2.setCenter(results_coods);
    infowindow_2.open(map_2,marker_2);
}

Javascript,html页面底部:              $(document).ready(function($){             GcodeAddress();             resizeMap();         });     

HTML(VB.Net):

    '-- Google Map

    g_map_text.Text = "<div id=""map_canvas"" style=""width: 225px; height: 225px;       position: relative;"" /></div>" & vbCrLf
    g_map_text.Text &= String.Format("<div id='map_text'      style=""display:none;width:150px;"">{0}</div>", LoadKantoor)
    g_map_text.Text &= String.Format("<div id='map_address' style='display:none;'      >{0}</div>", Bedrijf.Bedrijf("postalcode") & " " & Bedrijf.Bedrijf("city") & "," &      Bedrijf.Bedrijf("address"))

2 个答案:

答案 0 :(得分:2)

更简单的方法是使用CSS进行样式化。您需要使用自定义CSS将infoWindow的内容包装在div中。

使用Javascript:

marker.openInfoWindowHtml('<div class="iwContainer">' + yourContent + '</div>'); 

CSS:

.iwContainer { 
  width: 300px; 
  height: 200px; 
} 

您是否在调用open之前设置了infowindow的maxWidth,如上所述here

编辑:

我再次看了这个,看起来很好。我不明白为什么它不起作用。

您可以使用InfoBox.js吗?

API参考:http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html

下载JS:http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/

示例:http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/

让我知道你是怎么过的。

答案 1 :(得分:1)

也许您对使用此信息框感兴趣:

http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/examples/example.html/

您可以在此处应用css并使用示例轻松自定义