【问题标题】:trouble styling my google map我的谷歌地图样式有问题
【发布时间】:2011-12-16 17:57:04
【问题描述】:

我整个星期都在尝试设计我的谷歌地图的样式,并且正在转圈!我有我想使用的 JSON 值,但不知道如何将它们添加到 javascript 中!我还想让缩放栏控件位于窗口的右侧而不是左侧,因为我的地图是整页背景,所以左侧隐藏在网站内容 div 后面。

谁能帮忙?

:)

我要添加的 JSON 是:

[ { 样式器:[ { 饱和度:-90 },{ gamma:0.87 } ] } ]

我的地图代码是:

<script type="text/javascript">
//<![CDATA[

if (GBrowserIsCompatible()) { 

  // A function to create the marker and set up the event window
  // Dont try to unroll this function. It has to be here for the function closure
  // Each instance of the function preserves the contends of a different instance
  // of the "marker" and "html" variables which will be needed later when the event triggers.    
  function createMarker(point,html) {
    var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml(html);
    });
    return marker;
  }

  // Display the map, with some controls and set the initial location 
  var map = new GMap2(document.getElementById("map"));
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  map.setCenter(new GLatLng(50.826910965853585, -0.13648152351379395), 16);




  // Set up the markers with info windows 

  var point = new GLatLng(50.826910965853585, -0.13648152351379395);
  var marker = createMarker(point,'<div style="width:300px">text for pop up here....</div>')
  map.addOverlay(marker);





}







// display a warning if the browser was not compatible
else {
  alert("Sorry, the Google Maps API is not compatible with this browser");
}

// This Javascript is based on code provided by the
// Community Church Javascript Team
// http://www.bisphamchurch.org.uk/   
// http://econym.org.uk/gmap/

//]]>
</script>

【问题讨论】:

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


【解决方案1】:

试试:

var myStyles = [
  {
    featureType: "all",
    stylers: [ { saturation: -90 }, { gamma: 0.87 }
  }
];

map.setOptions({styles: myStyles });

基于:http://code.google.com/apis/maps/documentation/javascript/styling.html#styling_the_default_map

【讨论】:

    【解决方案2】:

    问题是您正在尝试使用 Maps API V2,它无法为您的地图设置样式。正如 graphicsdivine 所提到的,此代码将帮助您设置 Maps API V3 地图的样式: http://code.google.com/apis/maps/documentation/javascript/styling.html#styling_the_default_map

    由于 V2 已弃用,因此无论如何您都应该切换。要开始使用 V3 地图,请查看Maps API Basics page

    【讨论】:

    • 非常感谢您的反馈,我以为我在使用 V3 d'oh!
    猜你喜欢
    • 2013-08-06
    • 2013-05-20
    • 2013-03-21
    • 1970-01-01
    • 2018-04-12
    • 2011-03-17
    • 1970-01-01
    • 2013-06-13
    • 2011-11-26
    相关资源
    最近更新 更多