有人知道如何将GMap Static JSON转换为HTML网址吗?

时间:2014-04-18 11:26:52

标签: json google-maps url google-static-maps google-maps-styled

我从snazzymaps.com下载了一个示例样式的地图。我尝试转换为像http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=512x512&zoom=15&center=Chicago这样的网址,但我做得不好。我正试图改变下一个例子:

Example Google Map Styled Static

JSON看起来像这样:

styles: [

{"featureType":"poi","stylers":[{"visibility":"off"}]},{"stylers":[{"saturation":-70},{"lightness":37},{"gamma":1.15}]},{"elementType":"labels","stylers":[{"gamma":0.26},{"visibility":"off"}]},

{"featureType":"road","stylers":[{"lightness":0},{"saturation":0},{"hue":"#ffffff"},{"gamma":0}]},

{"featureType":"road","elementType":"labels.text.stroke","stylers":[{"visibility":"off"}]},

{"featureType":"road.arterial","elementType":"geometry","stylers":[{"lightness":20}]},

{"featureType":"road.highway","elementType":"geometry","stylers":[{"lightness":50},{"saturation":0},{"hue":"#ffffff"}]},

{"featureType":"administrative.province","stylers":[{"visibility":"on"},{"lightness":-50}]},

{"featureType":"administrative.province","elementType":"labels.text.stroke","stylers":[{"visibility":"off"}]},

{"featureType":"administrative.province","elementType":"labels.text","stylers":[{"lightness":20}]}

我已经改变了下一个,但它不起作用,我做错了!! :S

http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=512x512&zoom=15&center=Chicago&format=png&style=feature:poi%7Cvisibility:off%7Csaturation:-70%7Clightness:37%7Cgamma:1.15%7Celement:labels%7Cgamma:0.26%7Cvisibility:off&style=road%7Clightness:0%7Csaturation:0%7Chue:#ffffff%7Cgamma:0&style=road%7Celement:labels.text.stroke%7Cvisibility:off&style=road.arterial%7Celement:geometry%7Clightness:20&style=road.highway%7Celement:geometry%7Clightness:50%7Csaturation:0%7Chue:#ffffff&style=administrative.province%7Cvisibility:on%7Clightness:-50&style=administrative.province%7Celement:labels.text.stroke%7Cvisibility:off&style=administrative.province%7Celement:labels.text%7Clightness:20

如果有人可以给我一个建议,我将非常感激。

1 个答案:

答案 0 :(得分:5)

您应该阅读styled maps section of the Static Maps API Guide

  

定制的"样式" map由一个或多个指定样式组成,通过静态地图请求URL中的样式参数指示。 通过传递其他样式参数来指定其他样式。

因此您需要将多个&style=传递给该网址。 (每个功能/元素一个
你已经这样做了

对于颜色,您需要使用0xRRGGBB语法 同样在您的示例中,JSON中的第一行包含三个组。第二个是地图的全局样式,第三个是地图中的所有标签,而不是feature:poi。因此,您需要另一种针对feature:allelement:labels

的样式

您链接到的snazzymap示例会转换为(并非所有样式都包含在内

  • &style=feature:poi|visibility:off
  • &style=feature:all|saturation:-70|lightness:37|gamma:1.15
  • &style=element:labels|visibility:off
  • &style=feature:road|lightness:0|saturation:0|hue:0xffffff|gamma:0
  • &style=feature:road.highway|element:geometry|lightness:50|saturation:0|hue:0xffffff

请注意,将visibility设置为off时,操纵该功能/元素的任何其他属性没有意义

当添加到网址时,你会得到

http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=815x815&zoom=15&center=cicago&style=feature:poi|visibility:off&style=feature:all|saturation:-70|lightness:37|gamma:1.15&style=element:labels|visibility:off&style=feature:road|lightness:0|saturation:0|hue:0xffffff|gamma:0&style=feature:road.highway|element:geometry|lightness:50|saturation:0|hue:0xffffff


这里有一个将snazzymap json转换为Google Static Map网址的小工具..

工具http://jsfiddle.net/gaby/s6Dyp/