GameHost綜合論壇

標題: 【GOOGLE MAP API 基本教學】 [打印本頁]

作者: admin    時間: 2016-12-24 20:53
標題: 【GOOGLE MAP API 基本教學】
1.首先要去google API 新增一個專案並開通Google Maps JavaScript API

申請網址: https://console.developers.google.com/?hl=zh-tw

2. 新增一個憑證並且將 KEY 記下就可以使用囉



使用範例:

1.建立一個基本的 google map
  1.   <div id="map"></div>
  2.     <script>
  3.       function initMap() {
  4.         // Create a map object and specify the DOM element for display.
  5.         var map = new google.maps.Map(document.getElementById('map'), {
  6.           center: {lat: -34.397, lng: 150.644},
  7.           scrollwheel: false,
  8.           zoom: 8
  9.         });
  10.       }

  11.     </script>
  12.     <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"
  13.     async defer></script>
複製代碼
預覽畫面[attach]136[/attach]

2.建立信息座標

  1. var contentString = '<div id="content">你要輸入的資訊</div>';

  2.   var infowindow = new google.maps.InfoWindow({
  3.   content: contentString
  4.   });

  5.   var marker = new google.maps.Marker({
  6.   position: uluru,
  7.   map: map,
  8.   title: 'Uluru (Ayers Rock)'
  9.   });
  10.   marker.addListener('click', function() {
  11.   infowindow.open(map, marker);
  12.   });
複製代碼
預覽畫面[attach]135[/attach]

3.在地圖上畫線條
  1. var flightPlanCoordinates = [
  2.   {lat: 37.772, lng: -122.214},
  3.   {lat: 21.291, lng: -157.821},
  4.   {lat: -18.142, lng: 178.431},
  5.   {lat: -27.467, lng: 153.027}
  6.   ];
  7.   var flightPath = new google.maps.Polyline({
  8.   path: flightPlanCoordinates,
  9.   geodesic: true,
  10.   strokeColor: '#FF0000',
  11.   strokeOpacity: 1.0,
  12.   strokeWeight: 2
  13.   });

  14.   flightPath.setMap(map);
複製代碼

預覽畫面
[attach]134[/attach]









歡迎光臨 GameHost綜合論壇 (https://www.gamehost.cc/bbs/) Powered by Discuz! X3.2
抗ddos | 防ddos | 防禦ddos | 防ddos主機 | 天堂美工 | 設計 抗ddos主機 | 抗ddos | 抗ddos主機 | 抗攻擊論壇 | 天堂自動贊助 | 免費論壇 | 天堂私服 | 天堂123 | 台灣高抗ddos遊戲主機|無限防禦主機|抗攻擊主機|IP不黑洞-硬主機 | 抗ddos | 虛擬主機 | 實體主機 | vps | 網域註冊 | 抗攻擊遊戲主機 | ddos | 自動推文系統 |