Unity3d導入GoogleMap學習筆記


新建工程導入Google Maps for Unity包

打開自帶Demo場景,會發現報錯了。

大致看了看好像是不能解析HTTP。

然后找尋方法,點開README.txt.

 1 Google Maps for Unity
 2 ---------------------
 3 
 4 Support: forum.differentmethods.com
 5 
 6 Note: Google Maps for Unity requires UniWeb: http://u3d.as/1Cw
 7 This is because the Google Maps API requires the use and respect of cache
 8 control headers, which are unsupported by the builtin WWW class.
 9 
10 Because of this, this package will not work in WebPlayer builds as google
11 does not provide a Cross Domain policy server.
12 
13 Getting Started
14 ---------------
15 
16 1. Assign the GoogleMap component to your game object.
17 
18 2. Setup the parameters in the inspector.
19 2.1 If you want to control the center point and zoom level, make sure that
20     the Auto Locate Center box is unchecked. Otherwise the center point is
21     calculated using Markers and Path parameters.
22 
23 3. Each location field can be an address or longitude / latitude.
24 
25 4. The markers add pins onto the map, with a single letter label. This label
26 will only display on mid size markers.
27 
28 5. The paths add straight lines on the map, between a set of locations.
29 
30 6. For in depth information on how the GoogleMap component uses the Google
31 Maps API, see: 
32 https://developers.google.com/maps/documentation/staticmaps/#quick_example

可以看到README中標紅的第六行告訴我們,unity谷歌地圖需要uniweb支持。

然后繼續在應用商店搜索,然后下載導入包:

導入包后,可以看到無措可運行:

 

新建一個場景,添加一個Plane(平面)用來顯示地圖,添加一個直射光。(用於測試,沒做自適應,所以調整平面與相機的距離)

將GoogleMaps中的GoogleMap.cs腳本拖入Plane。

作如圖的參數修改:

取消Auto Lacate Center勾選。

填寫Center Location的經緯度(設置地圖顯示的中心)

設置Zoom值為16(用於顯示范圍)

設置Map Type為RoadMap

設置Size為1024

勾選Double Resolution

Markers是地圖中的標記組,設置個數為1(可以為多個),設置標記的大小,顏色和位置(經緯度)

Paths是地圖中的路徑組,設置個數為1(可以為多個),設置寬度,顏色,填充色(覆蓋的范圍),選擇路經地點(設置為3個地點的經緯度)

點擊運行如圖:

 

PS:獲取具體地理位置的經緯度方法:

點開網頁google地圖http://ditu.google.cn/maps?hl=zh-CN&tab=wl,找到要選擇的地點最大化,右鍵該地點,選擇"這兒是什么?",地點上方出現綠色箭頭,鼠標懸浮出現經緯度。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM