打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
使用Google Map v3地圖在的網站上

Google Maps JavaScript API v3允許你客制化googlemap的style,跟無聊和網站風格不達的googlemap地圖擺擺吧。

SnazzyMaps,找一個你喜歡的風格,當然你也可以自己手刻你要的style,選好後會得到下面的代碼,放在Head之前

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<script type="text/javascript">
    // When the window has finished loading create our google map below
    google.maps.event.addDomListener(window, 'load', init);
    function init() {
        // Basic options for a simple Google Map
        // For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions
        var mapOptions = {
            // How zoomed in you want the map to start at (always required)
            zoom: 11,
            // The latitude and longitude to center the map (always required)
            center: new google.maps.LatLng(40.6700, -73.9400), // New York
            // How you would like to style the map.
            // This is where you would paste any style found on Snazzy Maps.
            styles: [{featureType:"landscape",stylers:[{saturation:-100},{lightness:65},{visibility:"on"}]},{featureType:"poi",stylers:[{saturation:-100},{lightness:51},{visibility:"simplified"}]},{featureType:"road.highway",stylers:[{saturation:-100},{visibility:"simplified"}]},{featureType:"road.arterial",stylers:[{saturation:-100},{lightness:30},{visibility:"on"}]},{featureType:"road.local",stylers:[{saturation:-100},{lightness:40},{visibility:"on"}]},{featureType:"transit",stylers:[{saturation:-100},{visibility:"simplified"}]},{featureType:"administrative.province",stylers:[{visibility:"off"}]/**/},{featureType:"administrative.locality",stylers:[{visibility:"off"}]},{featureType:"administrative.neighborhood",stylers:[{visibility:"on"}]/**/},{featureType:"water",elementType:"labels",stylers:[{visibility:"on"},{lightness:-25},{saturation:-100}]},{featureType:"water",elementType:"geometry",stylers:[{hue:"#ffff00"},{lightness:-25},{saturation:-97}]}]
        };
        // Get the HTML DOM element that will contain your map
        // We are using a div with id="map" seen below in the <body>
        var mapElement = document.getElementById('map');
        // Create the Google Map using out element and options defined above
        var map = new google.maps.Map(mapElement, mapOptions);
    }
</script>

以上的代碼第一行,key=xxxxx,xxxxx就是你的API key,需要到google developer tool申請一個,教學看官方這個:申請google api說明文件

在你要現實地圖的地方插入DIV,對應以上js:

1
<div id="map"></div>

如果你要加一個Maker,在剛才的js代碼上多加一個Maker:

1
2
3
4
5
6
7
8
9
10
11
//其他js代碼
var map = new google.maps.Map(mapElement, mapOptions);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(22.27628, 114.17173),
map: map,
icon: 'your-icon-url' });
            }
//其他js代碼

LatLng,就是你google map地址的坐標,可以到「選找地圖坐標」網站找到。
當然你可以使用全部google map api的客制化選項:google map v3 api

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
JavaScript-Google Maps V3-我无法调解关闭
AngularJS指令封装高德地图组件
Google Map API使用详解(二十)——实现Google Map本地搜索框(下)
从Google Maps上看受灾的新奥尔良市
Google Map API V3 离线版
在leftlet 中使用echart和使用leaflet.ChineseTmsProviders图层的冲突
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服