How to import GPS location coordinates from Android device?

Discussion in 'Android Development' started by jsr2k1, Dec 5, 2010.

  1. jsr2k1

    jsr2k1

    New Member

    Joined:
    Aug 11, 2010
    Messages:
    24
    Hello, I tried to get latitude and longitude coordinates from 'Google Nexus One' and I failed.

    I used the LocationInfo struct, but I think there is something missing. I wrote an Update function attached to 'GUI Text' like this:

    void Update()
    {
    float lat, lon;

    LocationInfo li = new LocationInfo();

    lat = li.latitude;
    lon = li.longitude;

    guiText.text="LAT= "+ lat +"\nLON= " + lon;
    }
    Always returns 0.

    Any idea? Thanks in advance,

    Joel
  2. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Messages:
    514
    The GPS location info is currently not supported on Android.
  3. jsr2k1

    jsr2k1

    New Member

    Joined:
    Aug 11, 2010
    Messages:
    24
    Ok, thanks for the response.

    So, can I get GPS location info with a plugin using the NDK (or SDK) libraries from Android SDK?

    Joel
  4. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Messages:
    514
    Yes, by using the Java LocationManager interface (Android Dev Guide: Obtaining User Location) and a thin native wrapper between C# and Java, it shouldn't be too hard. But we will of course add this property, most probably in the very next release.
  5. Xandrilios

    Xandrilios

    New Member

    Joined:
    Apr 13, 2010
    Messages:
    3
    Hi,

    We have been trying to create a plugin + bridge to read GPS Location at school.
    We have run into a problem which is the following:

    Using Unity 3.1.0f4, we cannot get Java plugins to work.

    On Unity 3.0, we can run the (self-built using cygwin) example Java Plugin project, but get the following error in 3.1:
    "Unable to find javabridge" (where javabridge is the name of our DLL, as used in the example, libjavabridge.so)

    This problem occurs only on 3.1.0 for the Example project and for both 3.0 and 3.1 for our own created GPS Plugin.

    Is this a known problem in the recent version of Unity and/or might there be a common mistake we are making? Like: would this error occur when we have a faulty C++ bridge?


    This problem would of course be solved if we can use GPS directly in Unity, so please do your best!
  6. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Messages:
    514
    Did you account for the (3.1) re-arrangement in the Unity Plugin directory layout to put Android plugins under Assets/Plugins/Android (ie not only Assets/Plugins/)?
  7. Xandrilios

    Xandrilios

    New Member

    Joined:
    Apr 13, 2010
    Messages:
    3
    I did not, will try it now. Thank you!
  8. Xandrilios

    Xandrilios

    New Member

    Joined:
    Apr 13, 2010
    Messages:
    3
    Ok, I now screwed up my SDK install, will need to try at a later stage, sorry and thanks again.
  9. mikriloulou

    mikriloulou

    New Member

    Joined:
    Nov 30, 2010
    Messages:
    5
    Does anybody managed to obtain the GPS Location from Android already? If yes, could you please post some instructions on how to do this?
  10. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Messages:
    514
    GPS is supported in Unity 3.2 which is in alpha/beta state currently. But if you cant wait then the Android Developer Guide explains it in detail.
  11. Morothar

    Morothar

    New Member

    Joined:
    Dec 3, 2009
    Messages:
    14
    Hi!

    I successfully implemented an GPS plugin for a client of mine, which in turn asked if anyone would be willing to buy it here for about 100$.
    I can't decide to give it away for free, I'm sorry.
  12. krillmcrawl

    krillmcrawl

    New Member

    Joined:
    Feb 18, 2011
    Messages:
    29
    From release notes in Android section for 3.2:
    "Implemented Location Service (GPS/Wifi)."

    Lots of questions:)

    Have anyone tried the GPS functions in 3.2? I guess it now should work with LocationInfo? Does it work with compass as well? Any js examples on how to work with it? This might open up for some layar type features!
  13. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Messages:
    514
  14. dragon'78

    dragon'78

    New Member

    Joined:
    Nov 7, 2011
    Messages:
    1
  15. ina

    ina

    Member

    Joined:
    Nov 15, 2010
    Messages:
    329
    Does anyone know if LocationInfo or GPS/WiFiGPS works on Android yet? I've been getting 0's through this very simple guitxt update (both with loc reference declared in Update, and currently in Start)

    <code>
    var gtxt:GUIText;

    var loc:LocationInfo;

    function Start(){
    loc = new LocationInfo();
    }

    function Update () {

    //Debug.Log(loc.longitude);
    gtxt.text = displayLoc(loc.longitude, loc.latitude, loc.altitude, loc.horizontalAccuracy, loc.verticalAccuracy);
    }

    function displayLoc(lon:float,lat:float,alt:float,ha:float,va:float){
    return lon.ToString()+", "+lat.ToString()+" @ "+alt.ToString()+" | "+ha.ToString()+" "+va.ToString();
    }
    </code>
  16. ina

    ina

    Member

    Joined:
    Nov 15, 2010
    Messages:
    329
    It's a bit misleading that the only way to start location update is to call iPhoneSettings.StartLocationServiceUpdates(); ... even on the Android.