我可以通过 Unity 中的 API 添加静态谷歌地图,但我不能拖动它,也不能在其中添加标记。我只想知道当您通过 API 使用它时在静态地图上添加标记。
使用的给定脚本如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class googleAPI : MonoBehaviour
{
public RawImage img;
string url;
public float lat;
public float lon;
LocationInfo li;
public int zoom = 14;
public int mapWidth = 640;
public int mapHeight = 640;
public enum mapType { roadmap, satellite, hybrid, terrain }
public mapType mapSelected;
public int scale;
IEnumerator Map()
{
url = "https://maps.googleapis.com/maps/api/staticmap?center=" + lat + "," + lon +
"&zoom=" + zoom + "&size=" + mapWidth + "x" + mapHeight + "&scale=" + scale
+ "&maptype=" + mapSelected +
"&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318&markers=color:red%7Clabel:C%7C40.718217,-73.998284&key=AIzaSyCEELUzZC6wuQ6QRao4fHOLBpKQ-fPpkWI";
WWW www = new WWW(url);
yield return www;
img.texture = www.texture;
img.SetNativeSize();
StartCoroutine(Map());
}
// Use this for initialization
void Start()
{
img = gameObject.GetComponent<RawImage>();
StartCoroutine(Map());
}
// Update is called once per frame
void Update()
{
}
}
请注意这一行
标记=颜色:蓝色%7C标签:S%7C40.702147,-74.015794&标记=颜色:绿色%7Clabel:G%7C40.711614,-74.012318&标记=颜色:红色%7Clabel:C%7C40.718217,-73.998284
你应该为此添加纬度和长度 例:
标记=颜色:蓝色%7C标签:S%7C "+你的纬度+" , "+ 你的长 + "。