I am using Mapbox which shows the Users location on a Map. When I open the scene on an Android device (Samsung S8) it requests the permission but when you press Allow, it loads a grey screen. The rest of the assets are there (GUI) but it looks like the Map hasn’t initialized. if I close the App and reopen it, the Map now works.
Testing it on iOS, it all works fine.
I thought that if I could get the permission to come up when you first open the App - as opposed to when you open the Map scene - that it would have time for the Map to initialize.
Does anyone know how I can solve this issue?
I have this script on the Camera in the Map scene:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Locating : MonoBehaviour
{
private Vector2 targetCoordinates;
private Vector2 deviceCoordinates;
public static float lat;
public static float longi;
private bool ready = false;
private void Start(){
StartCoroutine(StartLocationService());
StartCoroutine(updateGPS());
}
public IEnumerator StartLocationService(){
if (!Input.location.isEnabledByUser){
Debug.Log("User has not enabled GPS");
yield break;
}
Input.location.Start();
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0){
yield return new WaitForSeconds(1);
maxWait--;
}
if (maxWait < 1){
Debug.Log("Timed out");
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed){
Debug.Log("Unable to determine device location");
yield break;
}
else{
longi = Input.location.lastData.longitude;
lat = Input.location.lastData.latitude;
}
ready = true;
}
public IEnumerator updateGPS(){
if (!Input.location.isEnabledByUser){
Debug.Log("User has not enabled GPS");
yield break;
}
float UPDATE_TIME = 1f;
WaitForSeconds updateTime = new WaitForSeconds(UPDATE_TIME);
while (true){
/* mapScript.Refresh();*/
longi = Input.location.lastData.longitude;
lat = Input.location.lastData.latitude;
SetLocation();
yield return updateTime;
}
}
void SetLocation(){
// radius.transform.position = new Vector3(0, 0, 6);
}
}