Расположение устройства Unity по широте и долготе - PullRequest
0 голосов
/ 04 октября 2018

Это то, что я пробовал, я хочу местоположение устройства Android (широта и долгота), но оно возвращает 0, 0.

private float userLatitude , userLongitude;

void Start()
{
    StartCoroutine(StartLocation());

    if(!Input.location.isEnabledByUser){
        Screen1ErrorMessage.ShowUserMessage("Location is Disabled.");
    }
}

IEnumerator StartLocation(){
    if (!Input.location.isEnabledByUser)
        Screen1ErrorMessage.ShowUserMessage("Enable Location to Play, else you can't be able to Join any Room");
        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)
    {
        Screen1ErrorMessage.ShowUserMessage("Timeout retrieving device location. Make sure you are connected to the internet");
        yield break;
    }

    if (Input.location.status == LocationServiceStatus.Failed)
    {
        Screen1ErrorMessage.ShowUserMessage("can't obtain device location, Enable Device Location to Play.");
        yield break;
    }
    else
    {
        userLatitude = Input.location.lastData.latitude ;
        userLongitude =  Input.location.lastData.longitude;
        isLocationAcquired = true;
        StartCoroutine(StartLocationUpdate());
    }

    Input.location.Stop();
}

IEnumerator StartLocationUpdate()
{
    string url = "--------------------------------------";

    Screen1ErrorMessage.ShowUserMessage("please wait...");

    WWWForm form = new WWWForm();

    form.AddField("UserId", PlayerPrefs.GetString("userId"));
    form.AddField("longitude", userLongitude.ToString());
    form.AddField("latitude", userLatitude.ToString());


    Debug.Log("Updation Location for User:"+PlayerPrefs.GetString("userId")+" : Latitude :" + userLatitude + " Longitude : "+userLongitude);

    UnityWebRequest www = UnityWebRequest.Post(url, form);
    yield return www.SendWebRequest();

    var Response = JSON.Parse(www.downloadHandler.text);
    if (Response["status"].Value == "true")
        // Screen1ErrorMessage.ShowUserMessage(result.message);
        Debug.Log("User Location Update Success");
    else
    {
        Debug.Log("User Location Update Failed Response ->" + Response.ToString());
    }
}

Я вызвал сопрограмму в моем методе запуска, должен ли я попробоватьна пробуждении тоже?Я пытаюсь вызвать другой результат, основанный на сопрограммах, но он никогда не вызывается.это означает, что существует проблема службы определения местоположения.

...