- Home /
Question by
mmukhtar1738 · Jul 02, 2018 at 06:36 PM ·
c#scripting problemapigoogle
modify given google API script to use phone gps location?
Hello
Im an absolute beginner in coding. I have this script here that I got of a youtube tutorial. currently the script uses Google API to display a google maps image of provided Lon/Lat gps coordinates.
I want to modify the script so it would use the phones current location (GPS coordinates) to display on the canvas. and even have it on the update function so it would change as the user walks/drives around. maybe even pinpoint the user with a pin.
its probably a simple solution but I'm a noob when it comes to writing scripts with no help. here is the script:
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=my API Key";
WWW www = new WWW (url);
yield return www;
img.texture = www.texture;
img.SetNativeSize ();
}
// Use this for initialization
void Start () {
img = gameObject.GetComponent<RawImage> ();
StartCoroutine (Map());
}
// Update is called once per frame
void Update () {
}
}
looking forward for your help. thanks a lot !
screen-shot-2018-07-02-at-112151-am.png
(250.4 kB)
Comment