Ich mache Pokemon Go-Like-Spiel. Ich möchte meine Karte überall aktualisieren, wo ich mein GPS verwende. Aber jetzt möchte ich die Koordinaten aktualisieren. Soll ich for
Schleife verwenden?Wie aktualisiere ich die Zentrumskoordinaten der Google Karte alle X Sekunden in Unity C#?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GoogleMap : MonoBehaviour {
public RawImage image;
string url;
public float lon, lat;
LocationInfo locationInfo;
public enum mapType {roadmap, satellite, hybrid, terrain}
public mapType mapSelected;
public int scale;
IEnumerator Map(){
//url = "https://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.&markers=color:red%7Clabel:C%7C40.718217,-73.998284&key=AIzaSyB41TT9I-4eK5zcl_n4tarK79QzgyVD4lc";
//url = "https://maps.googleapis.com/maps/api/staticmap?center=14.679046,120.540874&zoom=19&size=640x640&key=AIzaSyB41TT9I-4eK5zcl_n4tarK79QzgyVD4lc&scale=2";
url = "https://maps.googleapis.com/maps/api/staticmap?&key=AIzaSyB41TT9I-4eK5zcl_n4tarK79QzgyVD4lc¢er=14.679155295230377,120.54045265601641&zoom=18&format=png&maptype=roadmap&style=element:geometry%7Ccolor:0x1d2c4d&style=element:labels.text.fill%7Ccolor:0x8ec3b9&style=element:labels.text.stroke%7Ccolor:0x1a3646&style=feature:administrative.country%7Celement:geometry.stroke%7Ccolor:0x4b6878&style=feature:administrative.land_parcel%7Celement:labels.text.fill%7Ccolor:0x64779e&style=feature:administrative.province%7Celement:geometry.stroke%7Ccolor:0x4b6878&style=feature:landscape.man_made%7Celement:geometry.stroke%7Ccolor:0x334e87&style=feature:landscape.natural%7Celement:geometry%7Ccolor:0x023e58&style=feature:poi%7Celement:geometry%7Ccolor:0x283d6a&style=feature:poi%7Celement:labels.text.fill%7Ccolor:0x6f9ba5&style=feature:poi%7Celement:labels.text.stroke%7Ccolor:0x1d2c4d&style=feature:poi.business%7Cvisibility:off&style=feature:poi.park%7Celement:geometry.fill%7Ccolor:0x023e58&style=feature:poi.park%7Celement:labels.text%7Cvisibility:off&style=feature:poi.park%7Celement:labels.text.fill%7Ccolor:0x3C7680&style=feature:road%7Celement:geometry%7Ccolor:0x304a7d&style=feature:road%7Celement:labels.text.fill%7Ccolor:0x98a5be&style=feature:road%7Celement:labels.text.stroke%7Ccolor:0x1d2c4d&style=feature:road.highway%7Celement:geometry%7Ccolor:0x2c6675&style=feature:road.highway%7Celement:geometry.stroke%7Ccolor:0x255763&style=feature:road.highway%7Celement:labels.text.fill%7Ccolor:0xb0d5ce&style=feature:road.highway%7Celement:labels.text.stroke%7Ccolor:0x023e58&style=feature:transit%7Celement:labels.text.fill%7Ccolor:0x98a5be&style=feature:transit%7Celement:labels.text.stroke%7Ccolor:0x1d2c4d&style=feature:transit.line%7Celement:geometry.fill%7Ccolor:0x283d6a&style=feature:transit.station%7Celement:geometry%7Ccolor:0x3a4762&style=feature:water%7Celement:geometry%7Ccolor:0x0e1626&style=feature:water%7Celement:labels.text.fill%7Ccolor:0x4e6d70&size=640x640&scale=2";
WWW www = new WWW (url);
yield return www;
image.texture = www.texture;
image.SetNativeSize();
}
// Use this for initialization
void Start() {
image = gameObject.GetComponent<RawImage>();
StartCoroutine (Map());
}
// Update is called once per frame
void Update() {
}
}
Wie kann ich das mit meinem GPS verwenden? –
WWW www = neu WWW (url); führt jede Sekunde aus. Ist das nicht schlimm? –
Die gleiche Sache. Initialisiere das GPS zuerst in der 'Start'-Funktion wie [this] (https://docs.unity3d.com/ScriptReference/LocationService.Start.html) und benutze dann 'Input.location.lastData.latitude' und' Input.location. lastData.longitude ", um den Längen- und Breitengrad in der URL zu konstruieren und dann an die URL weiterzuleiten. – Programmer