|
最近因為剛好需要可以自定義Google地圖標誌及參數的Javascript語法,
所以網搜了一下,找到這個利用Google地圖API的實用程式,
在此分享給大家,若公司或個人需要自定義Google地圖標誌,這程式絕對可以派上用場...
不囉嗦,先看程式碼:- <div id="vat_canvas" style="width:100%;height:100%;"></div>
- <script type="text/javascript">
- <!--//
- var script = document.createElement('script') ;
- script.type = 'text/javascript' ;
- script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&'
- + 'callback=initialize&'
- + 'language=zh-TW' ;
- document.body.appendChild(script) ;
- var map = null ;
- var geoCoder = null ;
- var hide_address = '0' ;
- function initialize() {
- var latlng = new google.maps.LatLng(25.033663, 121.564644) ;
- var mapOptions = {
- zoom : 16 ,
- panControl : false ,
- zoomControl : true ,
- mapTypeControl : true ,
- scaleControl : true ,
- streetViewControl : true ,
- overviewMapControl : true ,
- rotateControl : true ,
- center : latlng
- };
- map = new google.maps.Map(document.getElementById('vat_canvas'), mapOptions) ;
- var html = '<div style="width:212px;height:55px;">'
- + '<font color="red">性感小野貓股份有限公司</font><BR>'
- + '<font color="green">統編:12345678</font><BR>'
- + '<font color="blue">地址:台北101性感路野貓巷520號</font></div>' ;
- var infowindow = new google.maps.InfoWindow({
- content : html
- });
- var marker = new google.maps.Marker({
- map : map ,
- position : latlng ,
- title : '性感小野貓股份有限公司'
- });
- infowindow.open(map,marker) ;
- }
- //-->
- </script>
複製代碼 再看效果:
大致上需要修改的地方不多:
1. var latlng = new google.maps.LatLng(25.033663, 121.564644) ;
須調整裡面的經緯度,可利用Google地圖直接查你要標誌位置的經緯度然後填入.
2. zoom : 16 ,
這數值為地圖的縮放程度,依照需求自己做調整吧.
3. var html = '<div style="width:212px;height:55px;">'
+ '<font color="red">性感小野貓股份有限公司</font><BR>'
+ '<font color="green">統編:12345678</font><BR>'
+ '<font color="blue">地址:台北101性感路野貓巷520號</font></div>' ;
調整自定義標誌的框架寬及高,內容文字跟文字顏色等,視需求自行調整.
4. title : '性感小野貓股份有限公司'
這是滑鼠移到標誌時會顯示的名稱,視需求自行調整吧.
這樣就大功告成啦!
下載程式碼:
def_map.htm
(1.32 KB, 下載次數: 1109)
|
+1
3
|