我正在使用Unity编写游戏,我需要加载静态地图。地图在编辑器和Android设备中正确显示,但在iOS设备中无法显示。它说网址不正确......我不知道解决方案是什么。有谁能够帮我?
我使用以下代码调用地图:
select name, employeeid,
trunc(sysdate - creation_date) + 1 counter
from your_table
这是调用网址的完整代码:
url= "http://maps.google.com/maps/api/staticmap?center="+fixLat+","+fixLon+"&zoom="+zoom+"&scale=2&size=640x640&style=feature:all|element:geometry|hue:0x00fff0|lightness:0|gamma:0.21|visibility:on&style=feature:all|element:labels|visibility:off&style=feature:landscape.man_made|element:geometry|color:0x133f42|visibility:on&style=feature:landscape.natural|element:geometry.fill|visibility:on|hue:0x00ffd2|saturation:35|lightness:0|gamma:0.5&style=feature:poi|element:geometry.fill|lightness:0|gamma:0.6|visibility:on&style=feature:poi.park|element:geometry|visibility:on|saturation:0|color:0x2e9470&style=feature:road|element:geometry.fill|visibility:on|color:0x05111a&style=feature:road|element:geometry.stroke|visibility:off&style=feature:transit|element:geometry|visibility:off"+key;
这些是截图。 Editor and Android device
答案 0 :(得分:0)
在您的问题中运行代码并能够复制您的问题。这是因为在iOS上使用http连接而不是https的新限制。就像我在评论中提到的那样,用WWW
替换UnityWebRequest
解决了这个问题。
此外,每次执行new Texture2D(1280, 1280, TextureFormat.RGB24, false);
时都会不必要地创建新纹理。这应该使用Unity的UI组件RawImage
来完成。在这种情况下,没有不必要的内存分配。
您需要对问题中的代码执行的操作就是删除WWW
API并使用UnityWebRequest
。同时删除Renderer
或Texture2D
并使用RawImage
显示您的地图。下面是我用来测试这个的简单测试脚本。它在Editor
,iOS
和可能所有其他平台上运行。
public class Gpsconnect : MonoBehaviour
{
public RawImage imageDisp;
public float fixLat = 42.3627f;
public float fixLon = -71.05686f;
public int zoom = 4;
public string key = "";
public Vector3 iniRef;
public Transform cam;
private Camera mycam;
private string url = "";
//Update Map with the corresponding map images for the current location ============================================
IEnumerator load()
{
yield return null;
mycam = Camera.main;
fixLat = ((360 / Mathf.PI) * Mathf.Atan(Mathf.Exp(0.00001567855943f * (cam.position.z - 3 * mycam.orthographicSize / 2 + iniRef.z)))) - 90;
fixLon = (18000 * (cam.position.x + iniRef.x)) / 20037508.34f;
//MAP ================================================================================
//Build a valid Google Maps tile request for the current location
url = "https://maps.google.com/maps/api/staticmap?center=" + fixLat + "," + fixLon + "&zoom=" + zoom + "&scale=2&size=640x640&style=feature:all|element:geometry|hue:0x00fff0|lightness:0|gamma:0.21|visibility:on&style=feature:all|element:labels|visibility:off&style=feature:landscape.man_made|element:geometry|color:0x133f42|visibility:on&style=feature:landscape.natural|element:geometry.fill|visibility:on|hue:0x00ffd2|saturation:35|lightness:0|gamma:0.5&style=feature:poi|element:geometry.fill|lightness:0|gamma:0.6|visibility:on&style=feature:poi.park|element:geometry|visibility:on|saturation:0|color:0x2e9470&style=feature:road|element:geometry.fill|visibility:on|color:0x05111a&style=feature:road|element:geometry.stroke|visibility:off&style=feature:transit|element:geometry|visibility:off" + "&sensor=false&key=" + key;
UnityWebRequest www = UnityWebRequest.GetTexture(url);
yield return www.Send();
Debug.Log("Done: ");
if (www.isError)
{
Debug.Log("Error while downloading image: " + www.error);
}
else
{
imageDisp.texture = ((DownloadHandlerTexture)www.downloadHandler).texture;
}
}
void Start()
{
StartCoroutine(load());
}
}