我可以通过Unity中的API添加静态的Google地图,但不能拖动它,也不能在其中添加标记。我只想在通过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()
{
}
}
答案 0 :(得分:0)
请注意这一行
markers =颜色:蓝色%7Clabel:S%7C40.702147,-74.015794&markers =颜色:绿色%7Clabel:G%7C40.711614,-74.012318&markers =颜色:红色%7Clabel:C%7C40.718217,- 73.998284
您应该为此添加lat和long 例如:
markers = color:blue%7Clabel:S%7C“ +您的纬度+”,“ +您的长+”。