I am working on a Unity3d for Android project. Using the documentation from Unity:
http://unity3d.com/support/documentation/ScriptReference/Input-location.html
I should be able to use Input.location to get access to GPS location data. But instead I get an error basically telling me the Input.location is not part of Unity.
Assets/Scripts/Prototype1.js(27,29): BCE0019: 'location' is not a
member of 'UnityEngine.Input'.
I've checked for updates and it tells me the system is fully up to date. I'm running version 3.4.2f3
Is the documentation outdated? Is there a different reference to the LocationService? How can I get the location data?
The files at unity3d.com contain the documentation for the most recent release Unity3D 3.5. If you look at your documentation in the local file system you won't find Input.location. Seems like they have changed the interface in Unity3D 3.5.
I haven't used GPS until now, maybe this thread and the links provided can throw some light on this:
How to import GPS location coordinates from Android device?
I found documentation to the old code, based in iPhoneSettings. This is the code I'm using now, it's not complete (doesn't respond to time out of the location service and other such well rounded behavior), but demonstrates the code.
function Start () {
locationStatus = LocationServiceStatus.Stopped;
StartCoroutine(startLocationService());
}
function Update () {
if(locationStatus == LocationServiceStatus.Running)
{
/*
lat = Input.location.latitude;
lon = Input.location.longitude;
alt = Input.location.altitude;
*/
lat = iPhoneInput.lastLocation.latitude;
lon = iPhoneInput.lastLocation.longitude;
alt = iPhoneInput.lastLocation.altitude;
}
}
function startLocationService()
{
//Input.location.Start(accuracy, distance);
iPhoneSettings.StartLocationServiceUpdates(accuracy, distance);
//while(Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) {
while(iPhoneSettings.locationServiceStatus == LocationServiceStatus.Initializing && maxWait > 0)
{
yield WaitForSeconds(1);
maxWait--;
}
//locationStatus = Input.location.status;
locationStatus = iPhoneSettings.locationServiceStatus;
}
Related
I am working on a personal project and I am using flutter to develop an app (cross platform) that reads in the user's health data from google fit (Android) or Apple Health. I am using this package and even the EXACT same code like in the documentation (I am currently only testing on Android):
Future fetchStepData() async {
int? steps;
// get steps for today (i.e., since midnight)
final now = DateTime.now();
final midnight = DateTime(now.year, now.month, now.day);
bool requested = await health.requestAuthorization([HealthDataType.STEPS]);
if (requested) {
try {
steps = await health.getTotalStepsInInterval(midnight, now);
} catch (error) {
print("Caught exception in getTotalStepsInInterval: $error");
}
print('Total number of steps: $steps');
setState(() {
_nofSteps = (steps == null) ? 0 : steps;
_state = (steps == null) ? AppState.NO_DATA : AppState.STEPS_READY;
});
} else {
print("Authorization not granted - error in authorization");
setState(() => _state = AppState.DATA_NOT_FETCHED);
}
}
Then I am calling this function with await and I also have inserted the correct permission in all Android Manifest files:
Also I set up an OAuth2 Client ID for the project and added my google account as a test user.
BUT THE FUNCTION SETS THE VARIABLE STEPS ALWAYS TO NULL? The boolean variable "requested" is true, so it seems like the actual connection is working?
I am really disappointed by myself guys and I really need help - THANK YOU!
I tried adding the correct android permissions, asking for permissions explicitly, different time intervalls but nothing worked for me, I always got a null value back.
I have tried to use XRSettings.LoadDeviceByName() but it never work. I have already check if the parameter device name is same as the current device name but nothing changes. Also, I have added the None in the sdk list
The XRSettings.loadedDeviceName is cardboard when initiating.
IEnumerator testThis() {
if (string.Compare(XRSettings.loadedDeviceName, "", true) != 0) {
XRSettings.LoadDeviceByName("none");
some_text.text = XRSettings.loadedDeviceName;
yield return new WaitForSeconds(1);
XRSettings.enabled = true;
some_text.text = "Device name " + XRSettings.loadedDeviceName;
}
}
IEnumerator temp() {
some_text.text = "Device name " + XRSettings.loadedDeviceName;
yield return new WaitForSeconds(10);
StartCoroutine(testThis());
}
No matter how I detect, the device name is still cardboard.
https://docs.unity3d.com/ScriptReference/XR.XRSettings.LoadDeviceByName.html
What I have done:
Make None as one of the Virtual Reality SDKs
Use XR-Plugin Management
2.1 Disable Virtual Reality Supported
2.2 Convert camera to XR-Rig
2.3 Use the code about turning VR off in XR-Plugin Management
2.4 Remarks: all the procedure in step 2 is work in iOS build but fail in android build.
2.5 https://docs.unity3d.com/Packages/com.unity.xr.management#4.0/manual/index.html
Tried XRSettings.LoadDeviceByName("none"); XRSettings.LoadDeviceByName(""); XRSettings.LoadDeviceByName("None");
Make sure that ''none'' is first in your VR SDK's, Then Cardboard.
I see a problem with your compare, there is no value
if (string.Compare(XRSettings.loadedDeviceName, "", true) != 0) {
If I understand correctly what you want to do, this code down here will receive a device name and will trigger the LoadDevice couroutine with this name.
public void VerifyDeviceName(string newDeviceName)
{
if (newDeviceName == "none")
{
Debug.Log("Will load none device");
StartCoroutine(LoadDevice(newDeviceName));
}
if (newDeviceName == "cardboard")
{
Debug.Log("Will load cardboard device");
StartCoroutine(LoadDevice(newDeviceName));
}
else
{
Debug.Log("Can't find device with name " + newDeviceName);
}
}
IEnumerator LoadDevice(string newDeviceName)
{
XRSettings.LoadDeviceByName(newDeviceName);
yield return new WaitForSeconds(10);
XRSettings.enabled = true;
Debug.Log("Loaded " + newDeviceName);
}
Note; This will obviously not work in editor you wil get a message saying you cannot trigger on/off vr in editor mode.
I just got through this by brute forcing it. The secret is not to Load device by name. If your trying to load "none" you should just initialize and deinitialize your XR loader.
Disable "Initialize XR on Startup" in Project Settings -> XR Plugin Management
In the code use these two methods
IEnumerator StartXR(){
yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
if(XRGeneralSettings.Instance.Manager.activeLoader == null){
Debug.Log("initialization FAILED");
}
else{
XRGeneralSettings.Instance.Manager.activeLoader.Start();
}
}
void StopXR(){
XRGeneralSettings.Instance.Manager.activeLoader.Stop();
XRGeneralSettings.Instance.Manager.activeLoader.Deinitialize();
}
(Sorry I am terrable at code snippits! I'm new to answering)
Then call these as you need them. It should turn on and turn off XR in your project
I'm starting using qt and I'm trying to get GPS coordinates from my ios and android with C++ following the exemple in official documentation.
The source is not null but the positionUpdated slot is never called.
Any tips would be welcomed, thank you.
ConnectionDeviceContextForDebug::ConnectionDeviceContextForDebug(StringDebugDisplayer* debugDisplayer):
_debugDisplayer(debugDisplayer)
{
QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this);
if(source){
connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(positionUpdated(QGeoPositionInfo)));
source->setUpdateInterval(100);
source->startUpdates();
_debugDisplayer->setText("source found");
//source->requestUpdate();
}
}
void ConnectionDeviceContextForDebug::positionUpdated(const QGeoPositionInfo &info)
{
_debugDisplayer->setText("position updated");
}
I am using Unity along with the Google Play Services Plugin for Unity found over here: https://github.com/playgameservices/play-games-plugin-for-unity
I am trying to access the players avatar to be included in a profile pic ingame. The problem is when I try accessing the Texture2D Social.localuser.image, it always returns null. Upon more research it seems that the code uses some kind of AvatarURL to find the image and that is the thing that is null. I used string.IsNullOrEmpty(AvatarURL) to check this. Does anyone know why AvatarURL is null, and/or how I can fix it. If not that, is there any alternative way to accessing the players avatar to use for a profile picture in my game.
Here is the code I used to test this:
PlayGamesPlatform.Activate();
//Authenticate User
Social.localUser.Authenticate((bool success) => {
if(success) {
Debug.Log("Successfully Authenticated");
Textures.profilePic = Sprite.Create(Social.localUser.image, new Rect(0, 0, Social.localUser.image.width, Social.localUser.image.height), new Vector2(0.5f, 0.5f));
SceneManager.LoadScene("Main Menu");
} else {
Debug.Log("Failed to Authenticate User");
SceneManager.LoadScene("ErrorCanNotSignIn");
}
});
The error happens when setting Textures.profilePic (Textures is another class I created that stores textures, and profilePic is a static Sprite variable in it). It says there is a NullReferenceException: Object reference not set to an instance of the object.
Again based on what I've seen, I think the source of the error seems to be the AvatarURL being null, as it causes this code, which I am pretty sure is what loads the image, not to run:
if (!mImageLoading && mImage == null && !string.IsNullOrEmpty(AvatarURL))
{
Debug.Log("Starting to load image: " + AvatarURL);
mImageLoading = true;
PlayGamesHelperObject.RunCoroutine(LoadImage());
}
Also if it's important, I am testing this on an android device.
Question answered by JeanLuc on this SO question
The implementation for Social.localUser.image of the Play Games Unity
Plugin returns always null.
The reason why the image returns null is because it's loaded asynchronously, so you'll need to wait for it.
Furthermore there's a bug where you first need to access Social.localUser.userName.
This code should be working:
Debug.Log(Social.localUser.userName); // you need to access Social.localUser.userName, otherwise the image will always return null
StartCoroutine(KeepCheckingAvatar());
// ...
private IEnumerator KeepCheckingAvatar()
{
float secondsOfTrying = 20;
float secondsPerAttempt = 0.2f;
while (secondsOfTrying > 0)
{
if (Social.localUser.image != null)
{
// Do something with freshly loaded image
break;
}
secondsOfTrying -= secondsPerAttempt;
yield return new WaitForSeconds(secondsPerAttempt);
}
}
Credits:
https://github.com/playgameservices/play-games-plugin-for-unity/issues/1056#issuecomment-212257972
I've problem with building search request on android.
ArrayList<ParseQuery<Entity>> queriesByCriteria = new ArrayList<>();
queriesByCriteria.add(ParseQuery.getQuery(Entity.class).whereContains("userName", criteria));
queriesByCriteria.add(ParseQuery.getQuery(Entity.class).whereContains("locationName", criteria));
queriesByCriteria.add(ParseQuery.getQuery(Entity.class).whereContains("descriptionBefore", criteria));
queriesByCriteria.add(ParseQuery.getQuery(Entity.class).whereContains("descriptionAfter", criteria));
ParseQuery<Entity> combinedQuery = ParseQuery.or(queriesByCriteria)
.orderByDescending("createdAt")
.whereEqualTo("done", true);
float mapRadius;
int mapUnits = preferences.getMapUnits();
if (mapUnits == MapUnitType.MAP_UNIT_KILOMETER) {
mapRadius = (preferences.getMapRadius());
} else {
mapRadius = 1.6f * (preferences.getMapRadius());
}
entities = combinedQuery
.whereWithinKilometers("location", new ParseGeoPoint(latLng.getLatitude(), latLng.getLongitude()), mapRadius)
.find();
So find() throws exception "com.parse.ParseException: internal error".
Version of Parse SDK is 1.7.1
Is it bug of parse.com or I do something wrong?
Yes, internal errors in SDK's refer to errors which are internal and not meant to be exposed to user's of the SDK. In this case, there is an edge case not handled internally by the find() method. My recommendation would be to go to the Parse suppport page and report this as a bug.