[英]Displaying Google Maps in Unity on mobile devices
有沒有一種方法可以在Unity 3D中但在移動設備(Android和iOS)上顯示Google Maps(甚至應該可以顯示其他地圖)?
甚至付費插件都可以。
您可以使用Unity的WWW.texture和Google的靜態地圖API將其地圖呈現為GameObject上的紋理。 在我的示例中,我使用了飛機,一點也不花哨。 我在示例中使用的圖片網址直接來自Google API頁面。 請注意,您需要使用自己的API密鑰 ,我將該值留為空白。 如果在沒有API密鑰的情況下運行我的示例,則會收到403錯誤。
using UnityEngine;
using System.Collections;
public class GoogleMaps : MonoBehaviour {
string exampleUrl = "http://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,"+
"New+York,NY&zoom=13&size=600x300&maptype=roadmap&markers=color:blue%7Clabel:S%7C40.702147,-74.015794"+
"&markers=color:green%7Clabel:G%7C40.711614,-74.012318"+
"&markers=color:red%7Ccolor:red%7Clabel:C%7C40.718217,-73.998284"+
"&sensor=false";
string key = "&key=YOUR_API_KEY"; //put your own API key here.
IEnumerator Start() {
WWW www = new WWW(exampleUrl+key);
yield return www;
renderer.material.mainTexture = www.texture;
}
}
我的插件Google Maps View正是這樣做的: https : //assetstore.unity.com/packages/tools/integration/google-maps-view-82542
適用於Android和iOS。 這是本機視圖,因此性能很棒。 唯一的限制是您不能在其頂部顯示Unity場景對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.