Search Unity

Location Service in Blackberry 10 not working

Discussion in 'BlackBerry' started by KepleriansTeam, Feb 4, 2015.

  1. KepleriansTeam

    KepleriansTeam

    Joined:
    Mar 14, 2014
    Posts:
    31
    Hi,

    I am trying to get Location data from Blackberry and i can't. I have BlackBerryGPS Permissions enabled, and the device returns 0. The surprise is that in the Maps App that comes installed with the device, didn`t get the proper position, it gets crazy giving random positions.

    Anyone has confirm that GPS in Unity with Blackberry10 is working?

    Thank you!
     
  2. AlexThibodeau

    AlexThibodeau

    Unity Technologies

    Joined:
    Jul 23, 2013
    Posts:
    309
    Hey there,

    What version of unity? What device?
     
  3. KepleriansTeam

    KepleriansTeam

    Joined:
    Mar 14, 2014
    Posts:
    31
    Hi,

    Unity 4.6.1p1 and the device is a BlackBerry Z10 v10.2.

    Thank you.
     
  4. AlexThibodeau

    AlexThibodeau

    Unity Technologies

    Joined:
    Jul 23, 2013
    Posts:
    309
    Hey dude,

    Just tried on my Z10 and Passport and I don't see the issue. On the passport it took a while... maybe about a minute or two to start getting readings. The Z10 displayed lat/long immediately. Does your phone have a SIM in it or connected to WiFi? I believe you need one or the other in order to receive a reading. With wifi I think you just get the lat/long of the nearest routing station if I recall correctly.

    Here's what I used for reference: http://docs.unity3d.com/ScriptReference/LocationService.Start.html

    -Alex
     
  5. KepleriansTeam

    KepleriansTeam

    Joined:
    Mar 14, 2014
    Posts:
    31
    Hi,

    It's a device without a SIM, but is connected to WiFi.

    Here is what I am using snippet:
    Code (CSharp):
    1. public IEnumerator StartMap(){
    2.         if (!Input.location.isEnabledByUser){
    3.             ////Debug.Log("Location service is not enabled.");
    4.             yield break;
    5.         }
    6.         Input.location.Start(15,4);
    7.         int maxWait = 6;
    8.         while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) {
    9.             yield return new WaitForSeconds(1);
    10.             maxWait--;
    11.         }
    12.         if (maxWait < 1) {
    13.             CancelLocalization();
    14.             yield break;
    15.         }
    16.         if (Input.location.status == LocationServiceStatus.Failed) {
    17.             CancelLocalization();
    18.             yield break;
    19.         }
    20.         LocationInfo info = Input.location.lastData;
    21.         lastData = new Vector2(info.longitude,info.latitude);
    22.         UseInfoToLocalize();
    23.         Input.location.Stop();
    24.     }
    I am Stopping the service and starting in order to receive the position only when you press a button. It should not be a problem, right?

    You think it needs more than 6 seconds to get data?
    It's an app for Android, iOS,WP and BlackBerry. In Android and iOS works correctly with this code.

    Thank you Alex,
     
    Last edited: Feb 6, 2015
  6. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Just out of interest when you start the map app do you get a location on that? If not, then Unity won't be able to get one either!
     
  7. KepleriansTeam

    KepleriansTeam

    Joined:
    Mar 14, 2014
    Posts:
    31
    Yes, it's the first thing I thought. But I wanted to have everything that is in my hand well done, because i haven't got more Blackberry devices...

    The map app gets a wrong position. About 400m of error or more :S. In Unity sometimes gives the same position(the wrong one), and other times don't enter in my map(It's a limited map of a preloaded city from gmaps).

    PD: Alex, I tried with the SIM card, and the Map app works more or less, but sometimes it is attempting to locate and never ends , but in Unity never locate correctly. I will do more tests...

    Thank you.
     
  8. AlexThibodeau

    AlexThibodeau

    Unity Technologies

    Joined:
    Jul 23, 2013
    Posts:
    309
    Are you calling Input.location.lastData.<lat or long> from an update?

    Here's what my code looks like:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class GetLocation : MonoBehaviour {
    5.     private string location;
    6.     // Use this for initialization
    7.     IEnumerator Start () {
    8.         if (!Input.location.isEnabledByUser)
    9.         {
    10.             Debug.Log("Location data is not enabled!");
    11.             return false;
    12.         }
    13.  
    14.         Input.location.Start();
    15.         int maxWait = 20;
    16.         while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
    17.         {
    18.             yield return new WaitForSeconds(1);
    19.             maxWait--;
    20.         }
    21.  
    22.         if (maxWait < 1 )
    23.         {
    24.             Debug.Log ("Timed out");
    25.             return false;
    26.         }
    27.  
    28.         if (Input.location.status == LocationServiceStatus.Failed)
    29.         {
    30.             Debug.Log ("Unable to determine device location");
    31.             return false;
    32.         }
    33.         else
    34.         {
    35.             Debug.Log("Lets do this!");
    36.         }
    37.     }
    38.  
    39.     // Update is called once per frame
    40.     void Update () {
    41.         location = "Lat: "+ Input.location.lastData.latitude + " Long: " + Input.location.lastData.longitude + "\nAltitude: " +
    42.             Input.location.lastData.altitude + " horizontal Accuracy: " + Input.location.lastData.horizontalAccuracy + "\nTimestamp: "+ Input.location.lastData.timestamp;
    43.     }
    44.  
    45.     void OnGUI()
    46.     {
    47.         GUI.Label(new Rect(100, 100, 500, 500), location);
    48.     }
    49. }
    I'm not sure if it matters "where" it's getting called from... I was just curious if you are attempting to access it on a semi-regular basis to see if it's changing. It was difficult to tell from your code sample.
     
  9. KepleriansTeam

    KepleriansTeam

    Joined:
    Mar 14, 2014
    Posts:
    31
    I am not getting the Input.location.lastData from Update, because as you see in my code, I am doing Input.Location.Stop() just after started, in order to get better performance.
    I used to have it in Update, but the data was very random, and I remember that doing "Start" the input.Location, I got more precision in the data.

    Isn't recommended to Stop de location? or i can call Input.location.lastData with the location service stopped?

    Thank you.