Unity3d GPS code
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//By Nathan
//Test code.
public class GPSLocationTest : MonoBehaviour
{
public float Latitude;
public float Longitude;
public float Oldlat;
public float Oldlon;
public AudioSource kickSource;
// Start is called before the first frame update
void Start()
{
kickSource = GetComponent<AudioSource>();
Latitude = Input.location.lastData.latitude;
Longitude = Input.location.lastData.longitude;
int oldLat;
int oldLon;
}
IEnumerator Start()
{
// First, check if user has location service enabled
if (!Input.location.isEnabledByUser)
yield break;
// Start service before querying location
Input.location.Start();
// Wait until service initializes
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return new WaitForSeconds(1);
maxWait--;
}
// Service didn't initialize in 20 seconds
if (maxWait < 1)
{
print("Timed out");
yield break;
}
// Connection has failed
if (Input.location.status == LocationServiceStatus.Failed)
{
print("Unable to determine device location");
yield break;
}
else
{
// Access granted and location value could be retrieved
print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
}
// Stop service if there is no need to query location updates continuously
Input.location.Stop();
}
// Update is called once per frame
void Update()
{
if (Input.location.status == LocationServiceStatus.Running)
{
Latitude = Input.location.lastData.latitude;
Longitude = Input.location.lastData.longitude;
kickSource.Play.sound();
}
do
{
#code to detect movement up
lat=NewLat;
newLat++;
#code to detect movement backwards
lat=NewLat;
newLat--;
#code to detect movement left
lat=NewLon;
newLon++;
#code to detect movement right
lat=NewLon;
newLon--;
}
while(newLat > lat || newLat < lat || newLon > lon || newLon < lon)
}
}
}
Also in C#:
- Title
- c sharp list of strings
- Category
- C#
- Title
- how to track a branch on github
- Category
- C#
- Title
- unity rigidbody constraints
- Category
- C#
- Title
- c# stringbuilder
- Category
- C#
- Title
- how to say or in c#
- Category
- C#
- Title
- c# delegate return value invoke
- Category
- C#
- Title
- how to parse a string to an integer c#
- Category
- C#
- Title
- how to get length of okobjectresult c#
- Category
- C#
- Title
- error CS0542
- Category
- C#
- Title
- c# how to take from a float
- Category
- C#
- Title
- How to look at an object unity
- Category
- C#
- Title
- unity quaternion
- Category
- C#
- Title
- asp.net core task iactionresult
- Category
- C#
- Title
- c# catch two exceptions in one block
- Category
- C#
- Title
- linq in c#
- Category
- C#
- Title
- c# check if string is all numbers
- Category
- C#
- Title
- how to convert float to int c#
- Category
- C#
- Title
- debug.log
- Category
- C#
- Title
- unity onclick addlistener
- Category
- C#
- Title
- c# enum default
- Category
- C#
- Title
- how to disable a gameObject unity c#
- Category
- C#
- Title
- scaffold-dbcontext sql server
- Category
- C#
- Title
- initialize enum with another enum c#
- Category
- C#
- Title
- move file from one folder to another c#
- Category
- C#
- Title
- sum of digits in c#
- Category
- C#
- Title
- c# get list of all class fields
- Category
- C#
- Title
- c# return multiple value unity
- Category
- C#
- Title
- CS0103 C# The name 'Request.Url.Scheme' does not exist in the current context
- Category
- C#
- Title
- .net core get image from url
- Category
- C#
- Title
- background color with opacity
- Category
- C#
- Title
- c# get gridview DataKeyNames
- Category
- C#
- Title
- uwp file open picker
- Category
- C#
- Title
- unity getcomponent
- Category
- C#
- Title
- first sentence letter capital in c#
- Category
- C#
- Title
- html hidden text
- Category
- C#
- Title
- linq c# where condition
- Category
- C#
- Title
- perlin noise unity
- Category
- C#
- Title
- how to flip selection in aseprite
- Category
- C#
- Title
- how to find a transform unity
- Category
- C#
- Title
- why is c# say ; expected
- Category
- C#
- Title
- grab reference from method parameter c#
- Category
- C#
- Title
- what type of variable is true or false in c#
- Category
- C#
- Title
- csharp first element of array
- Category
- C#
- Title
- how to change scenes in unity
- Category
- C#
- Title
- how to make % posibility to spawn an object C# in unity
- Category
- C#
- Title
- ignore fakeiteasy
- Category
- C#
- Title
- xamarin forms alarm
- Category
- C#
- Title
- C# get object property name
- Category
- C#
- Title
- sqlite connection c#
- Category
- C#
- Title
- unity get velocity at point
- Category
- C#
- Title
- https request c#
- Category
- C#
- Title
- mysql executeScalar only if successful
- Category
- C#
- Title
- unity hide mouse
- Category
- C#
- Title
- Unity how to put IEnumerator in update and loop once with yeild return new waitforseconds
- Category
- C#
- Title
- native-googlesignin configuration is null!?
- Category
- C#
- Title
- make string
- Category
- C#
- Title
- unitt only 1 number float
- Category
- C#
- Title
- how to make if statement c#
- Category
- C#
- Title
- unity set material
- Category
- C#
- Title
- how to make an object move in unity
- Category
- C#
- Title
- how to convert int to string unity c#
- Category
- C#
- Title
- create new object from generic c#
- Category
- C#
- Title
- unity connect to firebase
- Category
- C#
- Title
- defining vectors in c#
- Category
- C#
- Title
- downlaod file and use C#
- Category
- C#
- Title
- c# replace string case insensitive
- Category
- C#
- Title
- c# get full URL of page
- Category
- C#
- Title
- math class C# exponents
- Category
- C#
- Title
- c# string contains space
- Category
- C#
- Title
- c# number suffixes
- Category
- C#
- Title
- sum the digits in c#
- Category
- C#
- Title
- c# arraylist contains
- Category
- C#
- Title
- void start
- Category
- C#
- Title
- how to turn a string in a char list c#
- Category
- C#
- Title
- c# read all lines from filestream
- Category
- C#
- Title
- dynamic group by expression C#
- Category
- C#
- Title
- button commandfield commandargument pass textbox
- Category
- C#
- Title
- c# mongodb update multiple fields
- Category
- C#
- Title
- c# stop loop in method
- Category
- C#
- Title
- what is the and in c#
- Category
- C#
- Title
- c# abstract class
- Category
- C#
- Title
- c# delay
- Category
- C#
- Title
- asp.net core redirecttoaction with parameters
- Category
- C#
- Title
- set label position winforms
- Category
- C#
- Title
- unity particle system color
- Category
- C#
- Title
- unity how to change the text on a button
- Category
- C#
- Title
- c# convert dictionary to anonymous object
- Category
- C#
- Title
- never lose focus textbox c#
- Category
- C#
- Title
- c# superclass constructor
- Category
- C#
- Title
- unity simple fps controller
- Category
- C#
- Title
- switch case c# range
- Category
- C#
- Title
- remove all array elements c#
- Category
- C#
- Title
- Int64
- Category
- C#
- Title
- c# skip following code in loop
- Category
- C#
- Title
- C# resize window without title bar
- Category
- C#
- Title
- unity 2d Drag object
- Category
- C#
- Title
- c# get executable path
- Category
- C#
- Title
- ubuntu: how to open the terminal from c#
- Category
- C#
- Title
- c# serialize
- Category
- C#
- Title
- c# check file exists
- Category
- C#